Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.3k views
in Technique[技术] by (71.8m points)

Vue通过this调用全局自定义函数异常问题

Vue.prototype.whereGo 我在main.js中设置如下函数

image.png

然后调用处如下

image.png

控制台异常信息如下

image.png

麻烦各位看看这个是哪里出了问题

而且之前我是把Vue.prototype写在其他js文件中,在main.js中导入都可以识别,但是现在只要加上this就无法识别,这个突发情况是怎么一回事呢?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

@enter=“this.whereGo”,此处的this不是vue实例。
在vue,methods对象中写方法,是箭头函数写法,所以指向是vue实例。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...