admin管理员组文章数量:1435859
I am trying to make a VueJS app but I am failing even with the simplest examples. I am using Laravel 5.3 with pre-built support for VueJS (version 1, I tried version 2 as well).
Here is my Example.vue ponent
<template>
<div class="profile">
{{ name }}
</div>
</template>
<script>
export default {
data () {
return {
name: 'John Doe'
}
}
}
</script>
And here is the main code
Vueponent('example', require('./ponents/Example.vue'));
const app = new Vue({
el: '#app'
});
This is the error that shows up everytime in console:
[Vue warn]: Property or method "name" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option. (found in ponent )
Any ideas whats wrong? Thanks
I am trying to make a VueJS app but I am failing even with the simplest examples. I am using Laravel 5.3 with pre-built support for VueJS (version 1, I tried version 2 as well).
Here is my Example.vue ponent
<template>
<div class="profile">
{{ name }}
</div>
</template>
<script>
export default {
data () {
return {
name: 'John Doe'
}
}
}
</script>
And here is the main code
Vue.ponent('example', require('./ponents/Example.vue'));
const app = new Vue({
el: '#app'
});
This is the error that shows up everytime in console:
[Vue warn]: Property or method "name" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option. (found in ponent )
Any ideas whats wrong? Thanks
Share Improve this question edited Oct 8, 2016 at 15:06 m_pro_m asked Oct 8, 2016 at 12:03 m_pro_mm_pro_m 3404 silver badges12 bronze badges3 Answers
Reset to default 2In your script
tags instead of export default
use:
module.exports = {
data() {
return { counter: 1 }
}
}
This should work for you
Call the ponent inside your template
Vue.ponent('example', {
template: `<div class="profile">{{ name }}</div>`,
data () {
return {
name: 'John Doe'
}
}
})
const app = new Vue({
el: '#app'
})
<script src="https://unpkg./vue/dist/vue.js"></script>
<div id="app"><example></example></div>
The problem is that you are trying to load the ponent 'example' from that file but you didn't give a name to it. You should use:
<script>
export default {
name: 'example',
data() {
return {
name: 'John Doe'
}
}
}
</script>
Or load the ponent the following way (not sure if extension .vue is needed):
require('./exmaple').default();
If you are using Babel you can also load the ponents without giving them a name using this syntax:
import Example from ./example
Also checkout this post to get some more info in case you use Babel
本文标签: javascriptVueJS data() not workingStack Overflow
版权声明:本文标题:javascript - VueJS data() not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744523890a2610626.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论