看看你在methods中创建函数的时候是不是用了箭头函数,将其改为普通函数即可
想搞清原理的直接看最后
methods:{
demo1:() => {
#///使用this报错
},
demo2:function() {
#//可以正常使用this,在普通函数中创建箭头函数也可以正常使用this
}
}
英文原文:https://michaelnthiessen.com/this-is-undefined/
翻译版:https://www.jianshu.com/p/43637fa4fcee