想请教官方一个问题

发布于 7 年前作者 jiezou6647 次浏览最后编辑 7 年前来自 ask

关于小程序使用箭头函数,箭头函数中,this为什么是undefined?

困惑很久,希望能给个答复,谢谢

3 回复
taojin
taojin1 楼6 年前

你这样写,就不用在onLoad里面做处理了,

getUserFn(){

     console.log(this)

}

tao47
tao472 楼6 年前

如果是和 data同一层,再嵌套一层箭头,就跑到更上面去了,没有东西啦。这一层不需要箭头,直接this,就对了

tangjing
tangjing3 楼6 年前

在page外面定义个 let that, onLoad里面 that = this,然后可以用that了。。。