在请求配置文件中统一设置,加时间戳可以解决IE浏览器请求缓存的问题
这是request.js文件
import axios from "axios";
import config from "@config";
import store from "@store"
const instance = axios.create({
baseURL:config.baseURL,
headers:{
"Content-Type":"application/json",
"Caceh-Control":"no-cache"
},
timeout:config.timeout
}
instance.interceptors.request.use(config=>{
if(config.request){
config.baseURL = ""//写入不一样的请求地址
}
let getTimestamp =(new Date().getTime())
if(config.url.indexOf("?")>-1){
config.url = config.url + '×tamp='+getTimestamp;
}else{
config.url = config.url +"?×tamp="+getTimestamp;
}
if(store.state.token){
config.headers = config.headers || {}
config.headers.Authorization = store.state.token
config.headers["token"] = store.state.token
}
return config
}
请求接口api.js
import request from "./request.js"
export function test(data){
return request({
url:"",
method:get,
request:true,//在config中配置
data:data
})
config.js文件
export default{
baseURL:"",
timeout:300000,
hostname:{}
本文介绍了如何通过在请求配置文件中添加时间戳来解决Internet Explorer浏览器的请求缓存问题。在request.js文件中,我们创建了一个axios实例,并在请求拦截器中动态添加时间戳到URL,确保每次请求都是最新的。这种方法能够防止IE浏览器因缓存导致的数据过期问题。
1万+

被折叠的 条评论
为什么被折叠?



