vite build打包后页面不能正常访问解决方法

npm run build 后,生成了 dist 文件夹,将dist 文件 中 index.html 打开不能正常看到页面内容

在这里插入图片描述

解决方法:

1.配置 vite.config.ts / vite.config.js文件

配置 base: ‘./’

export default defineConfig({
    
    
  base: './',
  // 、、、省略其他配置
})

2.修改路由模式为 Hash 模式

import {
    
     createRouter, createWebHashHistory } from 'vue-router'

配置好后,重新 “npm run build”,会覆盖之前的 dist 文件夹,重新打开 index.html 就可以访问了

猜你喜欢

转载自blog.csdn.net/qq_39111074/article/details/130250331