Component's `data` property must be function restriction
See original GitHub issueWhat problem does this feature solve?
Take off this restriction would increase the consistency.
I understand that every component needs a copy of the data
object.
But can’t you just copy the data
object under the hood? Are there any benefits by using a function instead?
What does the proposed API look like?
Vue.component('foo', {
data: {
foo: 'bar'
}
});
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:6 (3 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 >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 >VueJS can't update component - Stack Overflow
The "editing" page has each object already filled as data already exist, ... The property must be added through Vue.set() or this.
Read more >vue/no-shared-component-data
When using the data property on a component (i.e. anywhere except on new Vue ), the value must be a function that returns...
Read more >Vue Components - Nice To Knows - 30 Days of Vue
One differentiation to keep in mind is that the data property of a Vue component should always be a function. Traditionally, we've defined...
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 Free
Top 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
Deep cloning objects (copy the data object under the hood) causes 1). heavy performance overhead 2). bloated code for a deep clone implementation. So it’s better to just use a function to create a fresh object every time.
Object.assign
is not deep