Vue3项目打包发布
作者:野牛程序员:2024-04-29 20:34:14网页设计阅读 3035
Vue3项目打包发布
在vite.config.js中添加一行代码
base: './',
完整代码如下:
import { fileURLToPath, URL } from 'node:url' import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' // https://vitejs.dev/config/ export default defineConfig({ base: './', plugins: [ vue(), ], resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) } } })
在router/index.js中把createWebHistory 换成createWebHashHistory
这里默认是createWebHistory
完整代码:
import { createRouter, createWebHashHistory } from 'vue-router' // import { createRouter, createWebHistory } from 'vue-router' import HomeView from '../views/HomeView.vue' const router = createRouter({ // history: createWebHistory(import.meta.env.BASE_URL), history: createWebHashHistory(process.env.BASE_URL), // 修改后 routes: [ { path: '/', name: 'home', component: HomeView }, { path: '/about', name: 'about', // route level code-splitting // this generates a separate chunk (About.[hash].js) for this route // which is lazy-loaded when the route is visited. component: () => import('../views/AboutView.vue') } ] }) export default router
野牛程序员教少儿编程与信息学奥赛-微信|电话:15892516892