[英]Using await in Vue interceptor
我如何在拦截器中使用等待? 我试过下面的代码,但它不打印值。
http.interceptors.push(async (req, next) => {
final value = await someAsyncFunction();
console.log(value);
})
我也尝试了这段代码,它有效但我想使用 await 因为我需要在它之后同步执行一些代码。
http.interceptors.push(async (req, next) => {
someAsyncFunction().then(value => console.log(value));
executeSomethingElse();
})
我认为你不能在拦截器上使用匿名 function,所以你应该这样写
http.interceptors.push(async function (req, next) {
await someAsyncFunction()
})
这是因为 Vue 无法访问后台的this
属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.