如果使用箭头功能,如何访问Vue上的数据



我们在方法上使用Vue和箭头函数。由于箭头函数没有this关键字,我们如何访问data,如listobject

export default {
data() {
return {
list: [],
object: {},
}
},
methods: {
onSubmit: (e) => {
//How can access this here?
//Im trying to access this.list
console.log(this);
}
},
}

提前谢谢。

在Vue组件中声明方法时,不建议使用箭头函数。

为什么不使用这样的东西呢?:

methods:{
onSubmit(e){
...
}
}

你可以参考其他关于主题的文章来获得详细信息,因为已经有很多关于同一主题的回复:

如何在回调中访问正确的"this"?

最新更新