0
点赞
收藏
分享

微信扫一扫

使用axios的拦截器给url添加时间戳参数

343d85639154 2022-03-23 阅读 25
javascript

使用axios的拦截器给url添加时间戳参数

axios.interceptors.request.use(
  config => {
    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
  }, function (error) {
    return Promise.reject(error)
  }
)

作用

  • 防止走缓存
举报

相关推荐

0 条评论