In components, data must be a function????
See original GitHub issue<div id="example1">
<simple-counter></simple-counter>
<simple-counter></simple-counter>
<simple-counter></simple-counter>
</div>
var data = { counter: 0 }
Moon.extend('simple-counter', {
template: `<button m-on:click="instance.set('counter', counter+1)">{{ counter }}</button>`,
data: data
})
new Moon({
root: '#example1',
})
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Why does the data property on a Vue component must be a ...
So, the reason why Vue forces the data property to be a function is that each instance of a component should have its...
Read more >Why must vue component data be a function? - Stack Overflow
It must be a function because otherwhise the data will be shared among all instances of the component, as objects are ...
Read more >Vue, why data must be a function - Flavio Copes
Using Vue you might surely asked yourself the question 'why must data be a function that returns an object, and not just an...
Read more >Why Vue.js data property in component must be a function?
Vue components are static, so this is the reason why every component must have a data object. If not, then all components would...
Read more >Vue.js: Why Components' Data Properties Must Be Functions
This post explains why components must contain a data property that is a function and not an object as with Vue instances.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It can be discussed if Moon should fatal when data is not a function (I think it shouldn’t, the Error in the console is enough), but it will work with the static data object. Just don’t complain that it shares state between components, if you do that 😉
For some reason i was sure that
Object.assign()
was ES5, but its not…