最近在做项目中遇到前端Vue在其他浏览器中使用正常,在IE浏览器中会出现数据更新了,但是接口请求数据不刷新列表的情况,在网上查询了需要vue配置请求头,设置请求拦截,如下所示:
//HTTPrequest拦截
axios.interceptors.request.use(config => {
if (needLoadingRequestCount === 0) {
const dom = document.getElementById('container')
const domMain = document.getElementsByClassName('avue-main')[0]
loadingInstance = Loading.service({
target: dom || domMain || document.body,
lock: true,
text: '数据加载中...',
spinner: 'el-icon-loading',
background: 'rgba(255, 255, 255, 0.9)',
})
}
needLoadingRequestCount++
if (config.data) {
jsonToHump(config.data)
}
if (config.params) {
jsonToHump(config.params)
}
ngStart() // start progress bar
const meta = (config.meta || {});
const isToken = meta.isToken === false;
const token = getToken()
const path = router.app.$route.path
//当使用Ie浏览器的时候,可能会出现数据更新了,但是接口请求数据不刷新的情况,加上下面这段代码即可
if (config.method === 'get' || config.method === 'GET') {
config.params = {
_t: new Date().getTime(),
...config.params
}
}
if (token && token != 'undefined' && !isToken) {
// const userInfo = JSON.parse(getToken())
// 让每个请求携带token--['Authorization']为自定义key 请根据实际情况自行修改
config.headers['Authorization'] = token
// config.headers['UserId'] = '123'
}
//headers中配置serialize为true开启序列化
if (config.method === 'post' && meta.isSerialize === true) {
config.data = serialize(config.data);
}
config.headers['Content-Type'] = 'application/json'
config.headers['OriginType'] = 'web'
// config.headers['Set-Cookie'] = 'SameSite=None;Secure'
return config
}, error => {
return Promise.reject(error)
});