在请求配置文件中统一设置,加时间戳可以解决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:{}