-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Closed
Labels
Description
Vue.js version
1.0.21
Reproduction Link
http://jsbin.com/doxonuviwe/edit?html
Steps to reproduce
- Register a Vue component with data function.
Vue.component('my-hello', {
data: function() {
console.log('hello')
return {};
}
});
new Vue({
el: 'body'
});
- Instantiate the component.
<my-hello></my-hello>
<my-hello></my-hello>
- You will see in the console (DevTool):
hello
hello
hello
hello
What is Expected?
Data function should be called twice since there is only two instances of Vue component.
What is actually happening?
Data function called four times.
Quick Fix
Set the data in the created
hook.
Vue.component('my-component', {
created: function() {
this.$data = {}; // Set your data here.
},
});
Hope this helpful.