关于Framework7 vue cli Ajax拦截器

关于Framework7 vue cli Ajax拦截器,ajax,vue.js,html-framework-7,Ajax,Vue.js,Html Framework 7,我想截获所有响应中状态代码为-1的所有ajax请求,并将其重定向到登录屏幕。但我一直无法监控它。我该怎么办?多谢各位 我的方法: app.js Framework7.Dom7(document).on('ajaxComplete',函数(e){ console.log('Monitored') })试试这个 创建新文件名interceptors.js interceptors.js import axios from 'axios'; import Vue from 'vue' export

我想截获所有响应中状态代码为-1的所有ajax请求,并将其重定向到登录屏幕。但我一直无法监控它。我该怎么办?多谢各位

我的方法: app.js
Framework7.Dom7(document).on('ajaxComplete',函数(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);
    });

}
import interceptorsSetup from './interceptors';
interceptorsSetup()
然后在你的
app.js
中导入
interceptors.js

app.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);
    });

}
import interceptorsSetup from './interceptors';
interceptorsSetup()

我正在使用app.request.post(URL、数据、成功、错误、数据类型)请求数据。如果我不需要axios怎么办?谢谢