Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

vue脚手架 axios async await问题

我在文本编辑器用axios的async await单独写了一个多异步获取接口数据的代码,但是我用在脚手架上面就不好使了。
image

image
但是不使用async await却可以 不知道问题出在哪了,搜索引擎没搜到相关内容,大佬带带我
image


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

1 Reply

0 votes
by (71.8m points)

this指向问题,
你用async时,this是谁调用就指向谁,getPlayList函数执行时没有调用者,那this.axios里的this就是undefined,
最简单的改法就是把 async function getPlayList () {} 改成 const getPlayList = async () => {} 的形式


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...