Vue3 打包通过相对路径访问空白的解决办法


参考

步骤

  1. /vue.config.js 配置打包路径,因为是相对路径访问,所以配置 publicPath 为空或 “./”
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  transpileDependencies: true,
  // 修改端口号:https://blog.csdn.net/qq_39313596/article/details/83544745
  devServer:{
    port: 8081
  },
  // https://cli.vuejs.org/zh/config/#publicpath
  publicPath: ""

})
  1. /src/router/index.ts 将默认路由类型 createWebHistory 改为 createWebHashHistory 路由
import { createRouter, createWebHistory, RouteRecordRaw,createWebHashHistory } from 'vue-router';
const router = createRouter({
	// history: createWebHistory(process.env.BASE_URL),
	history: createWebHashHistory(process.env.BASE_URL),
	routes
});


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM