vue 项目 run build 打包后页面空白 资源加载失败的问题
vue 项目 run build 打包后页面空白 资源加载失败的问题
·
今天在项目打包时发现的问题,vue 项目在运行 npm run build后,dist文件里的index.html打开后面空白,控制台报错如下:
出现这个错误,主要是路径引起的问题,解决办法:
// vue.config.js
module.exports = {
// 基本路径 这是最主要的点!!!
publicPath: './',
// 输出文件目录
outputDir: 'dist', // 默认dist
// 指定生成的 index.html 的输出路径 (相对于 outputDir)。也可以是一个绝对路径
indexPath: 'index.html', // Default: 'index.html'
}
如果依旧空白,控制台报错,那就有可能是路由的问题:
// router.js
import { createRouter, createWebHashHistory } from 'vue-router'
const routes = [ …… ]
const router = createRouter({
history: createWebHashHistory (), // 将 createWebHistory 替换成 createWebHashHistory 即可
routes
})
修改完以后,项目就能正常运行了,如果还有其他问题,根据控制台报错提示在进行解决即可
更多推荐
所有评论(0)