背景:
调用getvip方法需要先完成gettoken方法,获取token值
目标函数和当前函数都需加上async,await方法即可
methods: {
async gettoken() {
console.log(111)
var api = 'http://192.168.1.9/au?ame=vu&pword=n'
await axios.get(api).then((response) => {
this.token = response.data.data.token
})
},
async getvip() {
await this.gettoken() // 先获取token值
this.listLoading = true
var api = `http://192.168.1.9/history?mode=sreach&token=`
api = api + this.token
axios.post(api, this.postdata).then((response) => {
console.log(response.data.data)
this.data = response.data.data
this.listLoading = false
return
}, (err) => {
console.log(err)
})
},
}
网友评论