link822 link823 link824 link825 link826 link827 link828 link829 link830 link831 link832 link833 link834 link835 link836 link837 link838 link839 link840 link841 link842 link843 link844 link845 link846 link847 link848 link849 link850 link851 link852 link853 link854 link855 link856 link857 link858 link859 link860 link861 link862 link863 link864 link865 link866 link867 link868 link869 link870 link871 link872 link873 link874 link875 link876 link877 link878 link879 link880 link881 link882 link883 link884 link885 link886 link887 link888 link889 link890 link891 link892 link893 link894 link895 link896 link897 link898 link899 link900 link901 link902 link903 link904 link905 link906 link907 link908 link909 link910 link911 link912 link913 link914 link915 link916 link917 link918 link919 link920 link921 link922 link923 link924 link925 link926 link927 link928 link929 link930 link931 link932 link933 link934 link935 link936 link937 link938 link939 link940 link941 link942 link943 link944 link945 link946 link947 link948 link949 link950 link951 link952 link953 link954 link955 link956 link957 link958

[Vue.js] Vue.js - Unknown custom element <router-view>

I’m bit new to Vue.js and I’m trying to implement routing to the application but for some reason I’m facing an issue saying:

Unknown custom element: <router-view> - did you register the component
correctly? For recursive components, make sure to provide the “name” option

Am i registering the component wrongly? Any help is much appreciated, my code below:

app.js

import vue.js from ‘vue’
import AppLayout from ‘./theme/Layout.vue’
import router from ‘./router’

const app = new Vue({
router,
…AppLayout
})

export { app, router }

router.js

import vue.js from ‘Vue’
import VueRouter from ‘vue-router’
import Category from ‘./theme/Category.vue’
import Login from ‘./theme/Login.vue’

Vue.use(VueRouter)

const router = new VueRouter({
routes: [
{path: ‘/‘, component: Category},
{path: ‘/login’, component: Login}
]
})

export default router

Layout.vue

<template>
<div>
<app-header></app-header>
<section class=’main-section section’>
<div class=’container content’>
<router-view></router-view>
</div>
</section>
<app-footer></app-footer>
</div>
</template>
<script>
import AppHeader from ‘./AppHeader.vue’
import AppFooter from ‘./AppFooter.vue’
export default {
components: {
‘app-header’: AppHeader,
‘app-footer’: AppFooter
}
}
</script>
<style lang=’scss’>
$primary: #287ab1;
@import ‘~bulma’;

</style>

when following this guy’s code Here and his course

Solution :

Looks like Vue.use(VueRouter) is not doing it’s thing…

Which is like due to a case sensitivity with the vue.js import

import vue.js from ‘Vue’ // <— should be ‘vue’ NOT ‘Vue’
import VueRouter from ‘vue-router’
import Category from ‘./theme/Category.vue’
import Login from ‘./theme/Login.vue’

Vue.use(VueRouter)

const router = new VueRouter({
routes: [
{path: ‘/‘, component: Category},
{path: ‘/login’, component: Login}
]
})

[Vue.js] Nuxtjs - images can be loaded from HTML but not from css/scss files

Images on my page can be read from HTML file (for example when there is src tag and enter the relative path to image). For example:

<span class=”image”><img src=”../assets/theme/images/pic01.jpg” alt=””></span>

But when I load image as background via css/scss files, they’re not loaded. For example, this doesnt load image:

background-image: url(“/assets/theme/css/images/close.svg”);

@include vendor(‘background-image’, (‘linear-gradient(to top, #{$overlay}, #{$overlay})’, url(“/assets/theme/images/banner.jpg”)));

background-image: -moz-linear-gradient(to top, rgba(48, 54, 57, 0.2), rgba(48, 54, 57, 0.2)), url(“/assets/theme/images/banner.jpg”);

there is installed file-loader and url-loader. If I push file-loader and url-loader in extend section in nuxt.config, then images are not loaded from HTML too.

Solution :

You are using absolute path in the CSS files and nuxt doesnt translate them. Change the address to use @ alias:

background-image: url(“@/assets/theme/css/images/close.svg”);

[Vue.js] Multiple imports with vue

there is about 20 forms which get switched using a dynamic component

<component v-bind:is=”activeForm”></component

Rather than have about 20 of these

import Concentform from ‘../forms/concentForm’

and 20 declarations

export default {
components: {
Concentform,
anotherForm,
moreForms,
}
}

Can I do a mass import?

Solution :

Add index.js under ../forms with

import Concentform from ‘./concentForm’
export default {
Concentform
}

Import all in once (default) import forms from ‘../forms/‘
Set components

export default {
components: {
…forms,
otherComponent
}
}

[Vue.js] @blur tag clears value of input in Vue.js SPA compoonent

when converting an application that uses jQuery to a Vue.js SPA (without jQuery). Currently, some jQuery statements toggle the display of hidden div’s when the associated input field has focus, this is then hidden again on blur.

In a vue.js component there is added a data option of phoneNumberHasFocus which is set to true on field focus and false on blur. This works and the display of the div toggles on focus/blur.

However, any value typed into the input field is lost on blur.

export default {
name: ‘profile’,
data: function() {
return {
phoneNumberHasFocus: false
}
},
}
<div class=”col-md-6 col-sm-8”>
<div class=”input-area”>
<input type=”text” class=”form-control” placeholder=”Phone number” name=”phoneNumber” ref=”phoneNumber” :value=”user.userdetails.phoneNumber” @focus=”phoneNumberHasFocus=true” @blur=”phoneNumberHasFocus=false” />
</div>
<div v-show=”phoneNumberHasFocus” class=”help-text”>
Please provide a phone number here if youd like us to contact you by phone when you make an enquiry. Include the area code and extension if required.
</div>
</div>

Has anyone come across this issue before or have an alternative approach to toggling display of the div when the focus is on the input field?

Solution :

Add user.userdetails.phoneNumber to the data method

export default {
name: ‘profile’,
data: function() {
return {
phoneNumberHasFocus: false
user: {
userdetails: {
phoneNumber: ‘’
}
}
}
},
}

and use v-model for 2 way binding

<input type=”text” class=”form-control” v-model=”user.userdetails.phoneNumber” placeholder=”Phone number” name=”phoneNumber” ref=”phoneNumber” v-mo=”user.userdetails.phoneNumber” @focus=”phoneNumberHasFocus=true” @blur=”phoneNumberHasFocus=false” />

Solution 2:

I was able to resolve this problem by using the v-model directive and vuex-map-fields package to provide 2-way data binding to the store, which had the desired outcome of not clearing the field value on blur whilst hiding the related div with the help text.

<div class=”col-md-6 col-sm-8”>
<div class=”input-area”>
<input
type=”text” class=”form-control” placeholder=”Phone number”
name=”phoneNumber” ref=”phoneNumber” v-model=”phoneNumber”
@focus=”phoneNumberHasFocus=true” @blur=”phoneNumberHasFocus=false” />
</div>
<div v-show=”phoneNumberHasFocus” class=”help-text”>
Please provide a phone number here if youd like us to contact you by phone when you make an enquiry. Include the area code and extension if required.
</div>
</div>

<script>
import { mapFields } from ‘vuex-map-fields’;

export default {
name: ‘profile’,
data: function () {
return {
phoneNumberHasFocus: false,
}
},
computed: {
…mapFields([
‘user.userdetails.phoneNumber’,
]),
},
mounted: function () {
this.$store.dispatch(‘fetch_user’);
},
}
</script>

[Vue.js] Why my Vue.component is not rendered at HTML page?

i’m try to create a Vue.component, but HTML page is not render him (chrome does not give a errors). Please tell me where I made a mistake, what I’m doing wrong?

main.js:

Vue.component(‘product-type-component’, {
data() {
return {listProductType: []}
},
beforeMount(){
axios.get(‘http://localhost/admin/getListProductType')
.then(response => {
this.listProductType = response.data
})
},
template:’<option v-for=”index in listProductType” v-bind:value=”index.id + “/“ + index.name”>{index.name}</option>’
});

var vm = new Vue({
el: “#mainForm”,
data:{…},
beforeMount(){…},
methods:{…}
});

index.html

<!DOCTYPE html>
<html>
<head>
<meta charset=”utf-8”>
<link rel=”stylesheet” type=”text/css” href=”style/style.css”>
<title></title>
</head>
<body>
<div id=”mainForm”>
<select v-model=”selectItem”>
<product-type-component></product-type-component>
</select>
</div>
<script type=”text/javascript” src=”script\vue\vue.js”></script>
<script src=”script\axios\axios.min.js”></script>
<script type=”text/javascript” src=”script\main.js”></script>
</body>
</html>

Solution :

Hmm, I think you didnt realize that you add the vue.js as a node to the div#mainForm.

As a sibling the select node is not in scope of the SPA. And furthermore - when not overall sure - but I think during the mounting process all other nodes are removed from div#mainForm

It is more like this you want:

import vue.js from “vue”;

Vue.config.productionTip = false;
Vue.component(“product-type-component”, {
data() {
return { listProductType: [] };
},
beforeMount() {
// axios.get(‘http://localhost/admin/getListProductType')
// .then(response => {
// this.listProductType = response.data
// })
},

template: “<option “ + /* v-for… */ “>some option</option>”
});

new Vue({
el: “#app”,
template: `<select><product-type-component></product-type-component></select>`
});

[Vue.js] Import CSS using <link> tag in index.html Vuejs 2

I’m trying to include css file in index.html of vue2 app using link tag in head section.

It shows the call in inspect element network tab but response is blank. And the style is not applied in DOM.

When I import it in App.vue.js using import syntax, it included successfully.

Can anyone tell why it does not apply form index.html?

Solution :

VueJS, is not loving <link>..
you should use

<style src=”your/path/css/maradona.css”></style>

but if you insists just keep mine in /static/.

<link rel=”stylesheet” type=”text/css” href=”/static/youKnow.css”>

[Vue.js] vuetify child component property

to wrap a vuetify component into another one and select which property is configured from the parent.

I.e.Child component myToolbar

<template>
<v-toolbar app fixed></..>
</templare>

in parent I would like to configure the fact that the child uses a black, flat attribute like:

<my-toolbar black flat>…</my-toolbar>

How can I know from my child component which attributes where passed by the parent and enable them on the v-toolbar ?

I seem to be stuck with the fact that those are booleans so dark=true does not seem to work.

Any help would be welcome,

Thanks

Pat

Solution :

You can pass along all the attributes passed to the component to the Vuetify component using v-bind=”$attrs”

In the component template

<template>
<v-toolbar v-bind=”$attrs” app fixed></..>
</template>

Solution 2:

To elaborate on @Prashant - here is an example:

https://codesandbox.io/s/jll61on13

Topbar.vue

<template>
<v-toolbar v-bind=”$attrs”>
<slot/>
</v-toolbar>
</template>

App.vue

<template>
<v-app id=”inspire”>
<!– ————————————- –>
<!– app-topbar is the custom v-toolbar –>
<!– ————————————- –>
<br>Example 1
<app-topbar color=”primary”></app-topbar>
<!– ——————————————– –>
<br>
<span>
Example 2 - using
<code>slot</code>
</span>
<!– ————————————- –>
<!– app-topbar is the custom v-toolbar –>
<!– ————————————- –>
<app-topbar color=”primary”>
<v-toolbar-side-icon></v-toolbar-side-icon>
<v-toolbar-title class=”headline text-uppercase”>
<span>v u e</span>
<span class=”font-weight-light”>. j s</span>
</v-toolbar-title>
</app-topbar>
<!– ——————————————– –>
</v-app>
</template>

<script>
import Topbar from “./components/Topbar.vue”;
export default {
components: {
appTopbar: Topbar
},
data() {
return {};
}
};
</script>

[Vue.js] I set up CORS in my Rails app, but I still get the error

This question already has an answer here:

CORS Error: requests are only supported for protocol schemes: http etc

2 answers

there is it in the gemfile gem ‘rack-cors’, require: ‘rack/cors’. I did bundle install.

I also set it up in the config/initializers/cors.rb

Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins ‘*‘

resource ‘*‘,
headers: :any,
methods: [:get, :post, :put, :patch, :delete, :options, :head]
end
end

I did restart the server after.

Here is the error I get:

Access to XMLHttpRequest at ‘localhost:3000/articles’ from origin ‘http://localhost:8080' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

Here is my repo Portfolio_App.

Solution :

In the vue_portfolio/src/components/Articles.vue.js you have axios.get(‘localhost:3000/articles’), without protocol it is not absolute not relative, browser thinks that you’re trying to connect to host 3000 via protocol localhost and does not allow.

Change it to

axios.get(‘http://localhost:3000/articles')

or

axios.get(‘/articles’)

(the latter is for same-origin, CORS is not needed in this case)

[Vue.js] Vue.js - access to data from slot's component

there is a problem with accessing data from the component using slots.

Here’s my code:
codepen.io/anon/pen/BbOEZz

the line:
<p slot=”desc”>{ desc_01 }</p>
It started working and at the slot in the template displayed the value with date.

Can anyone help me with this matter?

Solution :

There are a couple of mistakes in the code

1.You don’t access data directly from the child. The child communicates with the parent via events, using emit.

You should

fire an event from the child
listen to the event on the parent
update a variable on the parent.

2.There is no desc_01 declared on the app. The template is executed in the context of the app and not the child, so you also need to define that property.

data () {
return {
desc_01: ‘’
}

}

I’ve added a code pen for this here.

[Vue.js] Associate .env file with vue.config.js

I would like to run different vue.config.js files based on my enviroment. Is it possible to point out a specific vue.config.js in an .env-file? Something like this:

.env.foo:

VUE_CONFIG=foo.vue.config.js

When I run npm run server — –mode foo to use the specified vue.js config.

Solution :

You need to use a package like dotenv to read the data from the .env file and use it in command-line.

I personally use something like this.

cmd:

npm run VUE_CONFIG=foo

js:

if (process.env.VUE_CONFIG === ‘foo’) {
require(‘foo.js’)
} else {
require(‘bar.js’)
}