VUE项目更新文件依然存在缓存
1.在static静态目录下新建version.json每次发版更改里面的版本号
2.
// 获取版本
this.$axios
.get(`http://vue地址/static/version.json`, {
headers: {
'Cache-Control': 'no-cache'
}
}) // 反正就是要请求到json文件的内容, 并且禁止缓存
.then((res) => {
const version = res.data.version
const clientVersion = localStorage.getItem('_version_')
console.log('最新版本>>', version)
console.log('当前版本>>', clientVersion)
// 和最新版本不同,刷新页面
if (version !== clientVersion) {
localStorage.setItem('_version_', version)
window.location.reload()
}
})
3.iis添加响应标头
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Expose-Headers" value="Date,date" />
<add name="Cache-Control" value="no-cache" />
</customHeaders>
</httpProtocol>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
</system.webServer>
</configuration>
浙公网安备 33010602011771号