1.打包后界面白屏不显示
在vite.config.ts中添加 base:'./',默认为base:'/'。
//
export default defineConfig({
plugins: [
vue(),
vueJsx(),
AutoImport({
imports:['vue','vue-router']
})
],
base:'./', //默认是'/' 打包时改为'./'
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
}
})
2.路由失效导致或public下图片资源不显示
路由失效导致进入页面时重定向没有生效
//路由失效导致进入页面时重定向没有生效
routes: [
{
path: '/home',
name: 'home',
component: () => import('../views/Home.vue')
},
{
path:'/',
redirect:'/home'
},
]
解决方案在router.ts中改为hash方式
history: createWebHashHistory(),