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.

Component's `data` property must be function restriction

See original GitHub issue

What 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
fnlctrlcommented, Apr 15, 2018

But can’t you just copy the data object under the hood? Are there any benefits by using a function instead?

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.

1reaction
jacekkarczmarczykcommented, Apr 15, 2018

Object.assign is not deep

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

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