Why component data must be a function

Insert picture description here
to sum up:

The first defined xx.vue file is a class after compilation. When this component is used in each place, it is equivalent to instantiating this class. Data is executed during instantiation. If it is not a function, an instance of each component The data is the same reference data. When 当该组件作为公共组件共享使用the data is changed in one place, all the data are changed together. If data is a function, the data of each instance is in the closure, it will not affect each

Guess you like

Origin blog.csdn.net/weixin_43638968/article/details/109282750