看看你在methods中創(chuàng)建函數(shù)的時(shí)候是不是用了箭頭函數(shù),將其改為普通函數(shù)即可
想搞清原理的直接看最后
methods:{
? ? ? ? ? ? demo1:() => {
? ? ? ? ? ? ? ? ? ? #///使用this報(bào)錯(cuò)
????????????},
? ? ? ? ? ? demo2:function() {
? ? ? ? ? ? ? ? ? ? #//可以正常使用this亮元,在普通函數(shù)中創(chuàng)建箭頭函數(shù)也可以正常使用this
????????????}
}
英文原文:https://michaelnthiessen.com/this-is-undefined/
翻譯版:http://www.reibang.com/p/43637fa4fcee