这下面是大概的代码结构
function LocationAgain() {
wx.ready(function() {
//微信的地理位置获取方法
wx.getLocation({
type: 'wgs84',
success: function(res) {
Ajax().then((res) {
if (res.data.code == 0) {
return true
}
})
}
})
})
}
function Ajax() {
return vm.$http.post(Url, {
local: params
})
}
Vue.http.interceptors.push((request, next) = >{
if (request.headers.map.needlocal) {
//用来判断是否需要获取地理位置
LocationAgain() //希望在这里调用这个函数后得到返回后再进行下面的操作
}
next((response) = >{
});
});
因为中间有好几步操作都是异步的,我该怎么样才能得知Ajax()这个函数请求完毕后再决定要不要执行拦截器中后续的操作
试着用Promise