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

[vue] 在vue中使用this应该注意哪些问题? #443

Open
haizhilin2013 opened this issue Jun 22, 2019 · 5 comments
Open

[vue] 在vue中使用this应该注意哪些问题? #443

haizhilin2013 opened this issue Jun 22, 2019 · 5 comments
Labels
vue vue

Comments

@haizhilin2013
Copy link
Collaborator

[vue] 在vue中使用this应该注意哪些问题?

@haizhilin2013 haizhilin2013 added the vue vue label Jun 22, 2019
@maozhuo123
Copy link

vue中使用匿名函数,会出现this指针改变。
解决方法
1.使用箭头函数
2.定义变量绑定this至vue对象

@xindiyang
Copy link

vue 的data避免使用箭头函数

@ZoeQCJ
Copy link

ZoeQCJ commented Sep 27, 2019

vue中methods中函数尽量不要使用箭头函数,会改变this指向,在vue-cli构建的项目中this会为undefined

@hwyeee
Copy link

hwyeee commented May 7, 2020

生命周期的钩子函数不能使用箭头函数,否者this不能指向vue实例

@hyj443
Copy link

hyj443 commented Oct 27, 2021

凡是vue里你写的函数中this能拿到当前组件实例的地方,都是vue在内部通过call改绑到vm实例的,但你换成箭头函数,它里面的this是无法改绑的,只继承上级的this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vue vue
Projects
None yet
Development

No branches or pull requests

6 participants