Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第 48 题:vue的data使用return包裹 #67

Open
ravencrown opened this issue Sep 17, 2019 · 0 comments
Open

第 48 题:vue的data使用return包裹 #67

ravencrown opened this issue Sep 17, 2019 · 0 comments

Comments

@ravencrown
Copy link
Owner

vue的data使用return包裹

  • 不使用return包裹的数据会在项目的全局可见,会造成变量污染
  • 使用return包裹后数据中变量只在当前组件中生效,不会影响其他组件
  • Object是引用数据类型,如果不用function返回,每个组件的data都是内存的同一个地址,一个数据改变了其他也改变了;
  • JavaScript只有函数构成作用域(注意理解作用域,只有函数{}构成作用域,对象的{}以及if(){}都不构成作用域),data是一个函数时,每个组件实例都有自己的作用域,每个实例相互独立,不会相互影响。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant