Я использую файл index.js для выполнения вызовов API в приложении vue.Есть ли способ добавить перехват или перед каждым вызовом, чтобы проверить, исправен ли мой токен, и перенаправить ли пользователя на вход в систему, если это не так?
import axios from 'axios'
const client = axios.create({
baseURL : 'http://myapi.com/api/',
json: true
})
export default {
async execute(method, resource, data) {
const token = localStorage.getItem('token')
return client({
method,
url: resource,
data,
crossdomain: true ,
headers: { "Authorization": `Bearer ${token}` }
}).then(req => {
return req.data
})
},
getResponses() {
return this.execute('get', 'GetResponses')
},
getAll(){
return this.execute('get', 'GetAll')
},