给我一个 vue3 多页面 配置 和 路由 代码
时间: 2023-06-08 15:05:54 浏览: 205
vue 配置多页面应用的示例代码
好的,以下是一个基本的 vue3 多页面配置和路由代码:
```javascript
// vue.config.js
module.exports = {
pages: {
page1: {
entry: "src/main1.js",
template: "public/page1.html",
filename: "page1.html"
},
page2: {
entry: "src/main2.js",
template: "public/page2.html",
filename: "page2.html"
}
},
configureWebpack: {
// 配置多页面同步使用的公共模块
optimization: {
splitChunks: {
cacheGroups: {
common: {
name: "common",
chunks: "initial",
minChunks: 2
}
}
}
}
}
}
```
```javascript
// src/main1.js 和 src/main2.js 都差不多,只是页面的挂载点不同
import { createApp } from "vue"
import App from "./App.vue"
import router from "./router"
createApp(App).use(router).mount("#app1")
```
```javascript
// router.js
import { createRouter, createWebHashHistory } from "vue-router"
import Page1 from "./views/Page1.vue"
import Page2 from "./views/Page2.vue"
const router = createRouter({
history: createWebHashHistory(),
routes: [
{ path: "/page1", component: Page1 },
{ path: "/page2", component: Page2 },
]
})
export default router
```
希望这些代码对你有所帮助!
阅读全文