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.0k 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 Answer

0 votes
by (71.8m points)

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


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

...