我想在所有响应中拦截状态代码为-1的所有ajax请求,并将其重定向到登录屏幕。但是我一直无法监视它。我该怎么办?谢谢。
我的方法:
app.js
Framework7.Dom7(document).on('ajaxComplete',function(e){
console.log('Monitored')
})
我想在所有响应中拦截状态代码为-1的所有ajax请求,并将其重定向到登录屏幕。但是我一直无法监视它。我该怎么办?谢谢。
我的方法:
app.js
Framework7.Dom7(document).on('ajaxComplete',function(e){
console.log('Monitored')
})
尝试一下。
创建一个新文件名interceptors.js
interceptors.js
import axios from 'axios';
import Vue from 'vue'
export default function setup() {
axios.interceptors.response.use(function (config) {
// Do something before the request is sent
return config;
},function (error) {
// Do something with request error
return Promise.reject(error);
});
}
然后在您的app.js
中导入interceptors.js
app.js
import interceptorsSetup from './interceptors';
interceptorsSetup()