vue项目打包完成后,打开index.html会出现空白页,有两个原因
1. publicPath配置应该是相对路径“./”,不能是“/”
module.exports = {
publicPath:"./",
//这里是配置的开发过程中解决跨域问题
devServer: {
open: true,
host: 'localhost',
port: 8080,
https:false,
proxy: {
'/api': {
//target里是我们需要访问的接口的域名
target: 'https://api.seanai.cn/wise/1',
ws: true,
changeOrigin: true,
pathRewrite: {
'^/api': '/' //请求的时候使用api去拼接剩下的具体请求的url即可
}
},
}
}
}
2.因为router中配置的是history路由,也就是mode:history,注释掉就可以了
const router = new VueRouter({
// mode: 'history',
base: process.env.BASE_URL,
routes
})
本文详细解析了Vue项目打包后出现空白页的问题及解决方法。主要关注两点:一是publicPath配置应为相对路径“./”,而非“/”。二是由于使用了history路由模式,需在生产环境中进行相应配置调整。
827

被折叠的 条评论
为什么被折叠?



