清除微信浏览器缓存
- 在axios的请求拦截器中添加以下代码,为每个请求增加时间戳,因为平时就用get和post,所以只写了两个,更多也可以继续else下去
if (config.method === 'get') {
config.params = config.data
config.params.t = +new Date();
delete config.data
} else if (config.method === 'post') {
(config.url as string) += `?t=${+new Date()}`;
}
- 重写vue-router的push、replace方法
// rewrite method start
let oldPush = router.push;
(router as any).oldPush = oldPush
router.push =
function (param: any): Promise<void | NavigationFailure | undefined> {
let rouQuery = {};
if (typeof param === 'object') {
if (param.query) {
param.query.t = +new Date()
} else {
param.query = {
t: +new Date()
}
}
rouQuery = param;
} else if (typeof param === 'string') {
rouQuery = {
path: param,
query: {
t: +new Date()
}
}
}
return oldPush(rouQuery)
}
let oldReplace = router.replace;
(router as any).oldReplace = oldReplace
router.replace =
function (param: any): Promise<void | NavigationFailure | undefined> {
let rouQuery = {};
if (typeof param === 'object') {
if (param.query) {
param.query.t = +new Date()
} else {
param.query = {
t: +new Date()
}
}
rouQuery = param;
} else if (typeof param === 'string') {
rouQuery = {
path: param,
query: {
t: +new Date()
}
}
}
return oldReplace(rouQuery)
}
// rewrite method end