报错:Uncaught SyntaxError: await is only valid in async functions and the top level bodies of modules
控制台:
代码:
const app = new Vue({
el: '#app',
data: {
},
created(){
const res = await axios.get('https://applet-base-api-t.itheima.net/bill',{
params:{
createor:'yang'
}
})
}
})
这是因为await要放在 async函数里面
在await外层方法前加一个async即可:
const app = new Vue({
el: '#app',
data: {
},
async created (){
const res = await axios.get('https://applet-base-api-t.itheima.net/bill',{
params:{
createor:'yang'
}
})
}
})