question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 6 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
sisoucommented, Jan 15, 2018

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 😉

0reactions
samuelgozicommented, Jan 22, 2018

For some reason i was sure that Object.assign() was ES5, but its not…

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found