vue3实战-如何解决vue3项目打包发布到服务器后访问页面显示空白问题

vue3实战-如何解决vue3项目打包发布到服务器后访问页面显示空白问题,第1张

1、处理vue.config.js文件中的publicPath,处理如下:
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
    publicPath: process.env.NODE_ENV === 'production' ? './' : '/',
	outputDir: 'dist',
	indexPath: 'index.html',
	lintOnSave: false,
    transpileDependencies: true,
})
2、处理router文件夹中的index.js文件,处理如下:采用修改后的部分
import { createRouter, createWebHistory, createWebHashHistory  } from 'vue-router';
import routes from "./routes";

const router = createRouter({
	//history: createWebHistory(process.env.BASE_URL),//默认时
	history: createWebHashHistory(process.env.BASE_URL),//修改后
	routes
})
export default router;
解决以上这两步,就解决vue3项目打包发布到服务器后访问页面显示空白问题

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1321506.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-12
下一篇2022-06-12

发表评论

登录后才能评论

评论列表(0条)

    保存