Why vue Vue of data is a function of the path alias alias + vue provided

Problem Description

Why vue assembly, our data property must be a function , () new Vue in the data except , because new Vue is only one data attribute.

the reason

Because components we pulled out, certainly has reusability, it will be multiple instances in the project. If the data attribute value is an object, then it's all instances will share the data, this is a very troublesome thing, you can not make sure that all your instances of property values ​​will not be repeated.

Our expectation is that each instance of a component can independently protect their data.

solution

We all know that in JavaScript, functions with a fast scope of independent features, external variables can not access its interior.

Imagine if we attribute data component is a function of his each instance will have its own scope of space , which is independent of data, will not affect each other between each instance.

Therefore, data attribute of the component must be a function.

 

Sometimes used in the project file path to the introduction of relatively deep, you need to use the "../../../xx.js" introduced a similar path this, this way is stupid, you can use webpack the path alias alias set up to solve .

Reference: https://www.jianshu.com/p/5faaa38774cf

Guess you like

Origin www.cnblogs.com/wangtong111/p/11425771.html