46

Vue(ES6)中的data属性为什么不能是一个对象?

 5 years ago
source link: https://juejin.im/post/5b4c0a715188251acc22fdd7
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
以下引官网原文:当一个组件被定义,data 必须声明为返回一个初始数据对象的函数,因为组件可能被用来创建多个实例。如果 data 仍然是一个纯粹的对象,则所有的实例将共享引用同一个数据对象!通过提供 data 函数,每次创建一个新实例后,我们能够调用 data

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK