Vue 多页面可以通过修改配置文件来控制 npm run serve
打开指定的页面。
- 在
vue.config.js
中配置pages
属性,指定每个页面的入口文件和输出文件。
module.exports = {
pages: {
index: {
entry:'src/pages/index/main.js',
template: 'public/index.html',
filename: 'index.html'
},
about: {
entry: 'src/pages/about/main.js',
template: 'public/about.html',
filename: 'about.html'
}
}
}
- 在 package.json 中配置命令,指定要打开哪个页面
"scripts": { "serve:index": "vue-cli-service serve --page index", "serve:about": "vue-cli-service serve --page about" },
然后在运行npm run serve:index 就会打开index页面了.