Vue Boilerplate 模板使用教程
1. 项目的目录结构及介绍
vue-boilerplate-template/
├── public/
│ ├── index.html
│ └── favicon.ico
├── src/
│ ├── assets/
│ ├── components/
│ ├── router/
│ ├── store/
│ ├── views/
│ ├── App.vue
│ └── main.js
├── .babelrc
├── .editorconfig
├── .eslintrc.js
├── .gitignore
├── .prettierrc
├── babel.config.js
├── package.json
├── README.md
└── vue.config.js
目录结构介绍
public/: 包含项目的公共资源,如index.html和favicon.ico。src/: 项目的源代码目录。assets/: 存放静态资源,如图片、字体等。components/: 存放 Vue 组件。router/: 存放 Vue Router 相关文件。store/: 存放 Vuex 相关文件。views/: 存放页面级别的组件。App.vue: 项目的根组件。main.js: 项目的入口文件。
.babelrc: Babel 配置文件。.editorconfig: 编辑器配置文件。.eslintrc.js: ESLint 配置文件。.gitignore: Git 忽略文件配置。.prettierrc: Prettier 配置文件。babel.config.js: Babel 配置文件。package.json: 项目的依赖和脚本配置。README.md: 项目说明文档。vue.config.js: Vue CLI 配置文件。
2. 项目的启动文件介绍
main.js
import Vue from 'vue';
import App from './App.vue';
import router from './router';
import store from './store';
Vue.config.productionTip = false;
new Vue({
router,
store,
render: h => h(App)
}).$mount('#app');
- 引入 Vue 和项目的主要组件
App.vue。 - 引入路由配置
router和状态管理配置store。 - 创建 Vue 实例并挂载到
#app元素上。
3. 项目的配置文件介绍
vue.config.js
module.exports = {
devServer: {
proxy: {
'/api': {
target: 'http://localhost:3000',
changeOrigin: true,
pathRewrite: { '^/api': '' }
}
}
}
};
devServer: 开发服务器配置。proxy: 配置 API 请求的代理,将/api请求代理到http://localhost:3000。
package.json
{
"name": "vue-boilerplate-template",
"version": "1.0.0",
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"vue": "^2.6.11",
"vue-router": "^3.2.0",
"vuex": "^3.4.0"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^4.5.0",
"@vue/cli-plugin-eslint": "^4.5.0",
"@vue/cli-service": "^4.5.0",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.2.2",
"vue-template-compiler": "^2.6.11"
}
}
scripts: 定义项目的脚本命令,如serve、build和lint。dependencies: 项目的生产依赖。devDependencies: 项目的开发依赖
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考



