Skip to content

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

Open
@haizhilin2013

Description

@haizhilin2013
Collaborator

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

Activity

maozhuo123

maozhuo123 commented on Jul 3, 2019

@maozhuo123

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

xindiyang

xindiyang commented on Sep 11, 2019

@xindiyang

vue 的data避免使用箭头函数

ZoeQCJ

ZoeQCJ commented on Sep 27, 2019

@ZoeQCJ

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

hwyeee

hwyeee commented on May 7, 2020

@hwyeee

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

hyj443

hyj443 commented on Oct 27, 2021

@hyj443

凡是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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @haizhilin2013@maozhuo123@xindiyang@hyj443@ZoeQCJ

        Issue actions

          [vue] 在vue中使用this应该注意哪些问题? · Issue #443 · haizlin/fe-interview