我是ES7的新手
我想在Vue.js中使用async / await
这是我的代码
created (){
this.getA()
console.log(2)
this.getB()
},
methods : {
getA (){
console.log(1)
},
getB (){
console.log(3)
}
}
Run Code Online (Sandbox Code Playgroud)
它返回
1
2
3
Run Code Online (Sandbox Code Playgroud)
但是当我与axios一起使用时
created (){
this.getA()
console.log(2)
this.getB()
},
methods : {
getA (){
$axios.post(`/getA`,params){
.then((result) => {
console.log(1)
})
},
getB (){
console.log(3)
}
}
Run Code Online (Sandbox Code Playgroud)
它返回
2
3
1
Run Code Online (Sandbox Code Playgroud)
所以我想在该代码中添加异步/等待。
如何使用异步/等待?
我试过了
async created (){
await this.getA()
console.log(2)
await this.getB()
},
methods : {
getA (){
$axios.post(`/getA`,params){
.then((result) => {
console.log(1)
})
},
getB …Run Code Online (Sandbox Code Playgroud)