import axios from 'axios'
import cookie from 'js-cookie'
const options = {
baseURL: window.location.protocol + process.env.BASE_API,
headers: {},
timeout: 20000
}
const fetch = axios.create(options)
// request拦截器
fetch.interceptors.request.use(config => {
if (cookie.get('jwt')) {
config.headers.Authorization = cookie.get('jwt')
}
try {
config.headers.Authorization = window.JSBridge.getToken()
} catch (err) {
console.error(err)
}
return config
}, error => {
Promise.reject(error)
})
参考 https://www.jianshu.com/p/ff8541e0976a