一、修改配置文件

build/ webpack.prod.cong.js

js 、css文件名称增加时间戳。
在这里插入图片描述
在这里插入图片描述

此时上线部署的话,正在访问的页面可能会报错。
在这里插入图片描述

二、监听报错,进行处理

/router/index.js

vueRouter.onError((error) => {
    const pattern = /Loading chunk (\d)+ failed/g;
    const isChunkLoadFailed = error.message.match(pattern);
    if (isChunkLoadFailed) {
        window.location.reload();
    } else {
        console.log(error)
    }
});

监听到报错的话,会重载。

=============================================================

方法2:

在这里插入图片描述
build >webpack.prod.conf.js:
template: ‘index.html’, 处, 增加一行: hash: new Date().getTime()

/router/index.js

vueRouter.onError((error) => {
    const pattern = /Loading chunk (\d)+ failed/g;
    const isChunkLoadFailed = error.message.match(pattern);
    if (isChunkLoadFailed) {
        window.location.reload();
    } else {
        console.log(error)
    }
});

监听到报错的话,会重载。

打包之后,index.html引用的js和css 会增加后缀。
在这里插入图片描述
更新版本后, 只要切换路由,就会重新加载。

Logo

前往低代码交流专区

更多推荐