Now, I am using module.export instead of export default it works!
Oct 6, 2016
8
Level 2
Using Vue Router with .vue component files
Hi there, I have a problem when using router components as .vue files. Explanation below:
I use these dependencies:
"vue": "^2.0.1",
"vue-router": "^2.0.0",
"laravel-elixir-vue-2": "^0.2.0"
Everyhing is ok when I define router like below:
const router = new VueRouter({
routes: [
{ path: '/', component: {
template: '<div>Home</div>',
created() {
console.log('a')
}
} },
{ path: '/pricing', component: {
template: '<div>Pricing</div>',
created() {
console.log('b')
}
} }
]
});
But when I tried to seperate components in .vue files, scripts in vue files are not compiling. Like below:
import Home from './routes/Home.vue';
import Pricing from './routes/Pricing.vue';
const router = new VueRouter({
routes: [
{ path: '/', component: Home },
{ path: '/pricing', component: Pricing }
]
});
Home.vue:
<template>
<div>
Home
</div>
</template>
<script>
export default{
data(){
return {
user: 'asd'
}
},
created() {
console.log('a')
}
}
</script>
Please or to participate in this conversation.