默认打包出来的项目运行在根目录可以正常显示,如果在二级域名下就会显示空白,是因资源引用路径及路由模式不同导致的,需要做以下两步配置:
一、修改publicPath
vue.config.js
module.exports = {
publicPath: process.env.NODE_ENV === 'production' ? './' : '/', //打包到生产环境使用./
...
};
二、修改路由模式
src/router/index.js
const router = new VueRouter({
// mode: 'history', // 这句注释后默认为hash模式
...
});