Vue项目写完后,执行 npm run build 打包命令 打包完成后
打开 dist index.html 后发现页面显示白屏(一般是路径问题)
情况一: 在项目根目录上创建vue.config.js
配置publicPath 如下所示:
module.export = {
publicPath: './' // 具体路径根据项目中的实际路径而定
}
情况二: vue-router的mode:'history'配置会影响打包后的链接地址
var router = new Router({
// mode: 'history'
})
将mode:'history'注释或者改成mode:'hash'即可.
如果使用history模式上线,必须要服务端在服务器上有对应的模式才能使用history
vue-router中mode(配置路由模式)有三个可选值:
1. hash: 使用 URL hash 值来作路由。支持所有浏览器,包括不支持 HTML5 History Api 的浏览器。
2. his