vue ie浏览器 页面缓存 不请求接口

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zyq19930325/article/details/88551300

IE浏览器第一次发请求没有问题,再发送请求时,当参数一样时,浏览器会直接使用缓存数据. 导致页面 还是原来的页面

所以在axios 请求头 添加时间戳

const service = axios.create({
  // api的base_url
  baseURL: process.env.BASE_API
  // timeout: 30000 // request timeout
})
// request拦截器
service.interceptors.request.use(config => {
  // Do something before request is sent
  if (!localStorage.getItem('accessToken')) {
    config.headers.Authorization = 'Basic dnVlOnZ1ZQ=='
  } else {
    config.headers.Authorization = 'Bearer ' + localStorage.getItem('accessToken')
  }
  if (config.headers.Authorization === 'Basic dnVlOnZ1ZQ==' && window.location.hash !== '#/') {
    if (window.location.hash !== '#/retrievePassword') {
      Message.error('凭证过期,请重新登录!')
      router.replace('/')
      location.reload()
    }
  }
  // 时间戳
  if (config.method === 'post') {
    config.data = {
      ...config.data,
      t: Date.parse(new Date()) / 1000
    }
  } else if (config.method === 'get') {
    config.params = {
      t: Date.parse(new Date()) / 1000,
      ...config.params
    }
  }
  return config
}, error => {
  // Do something with request error
  // console.log('request拦截器1', error) // for debug
  Promise.reject(error)
})

猜你喜欢

转载自blog.csdn.net/zyq19930325/article/details/88551300