О Framework7-vue-cli Ajax Interceptor - PullRequest
       26

О Framework7-vue-cli Ajax Interceptor

0 голосов
/ 06 ноября 2019

Я хочу перехватить все запросы Ajax с кодом состояния -1 во всех ответах и ​​перенаправить их на экран входа в систему. Но я не смог его контролировать. Что я должен делать? Спасибо.

Мой метод: app.js Framework7.Dom7(document).on('ajaxComplete', function(e){ console.log('Monitored') })

1 Ответ

1 голос
/ 06 ноября 2019

Попробуй это.

Создайте новое имя файла 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()
...