Open xxxs opened 3 years ago
Use axios, How to set the request timeout period ?
export default ({ app, $axios, store, redirect, req }) => { const axios = $axios axios.defaults.timeout = 30000; // 30s This does not take effect axios.onRequest((config) => { const reqConfig = config const { token } = store.state if (token) { reqConfig.headers = { Authorization: `Bearer ${token}` } } return reqConfig }) axios.onError((err) => { console.log(err.response) const apiUrl = err.response.config.url if ( err.response.status === 401 && err.response.data.error === 'invalid_token' ) { store.dispatch('userLogout') } return Promise.reject(err) }) }
Use axios, How to set the request timeout period ?