合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
从零开始,手把手教程(来源于网络上做得比较典型的实例,做了一些加工,便于新手理解); ## 一、创建项目 ``` vue init webpack ray ``` ![](https://img.kancloud.cn/e9/70/e970a7341fee860ee2344ee91ec131db_677x457.png) ``` npm run dev ``` ![](https://img.kancloud.cn/e6/bd/e6bd830d22704014fc42cde28bbaf20c_677x457.png) [http://localhost:8080/#/](http://localhost:8080/#/) ![](https://img.kancloud.cn/2d/7e/2d7e933f12721f2c7d5a44ec1836763c_1366x736.png) ## 二、为项目增加第三方库支持 ``` npm install --save axios npm install --save element-ui npm install --save font-awesome npm install --save-dev node-sass npm install --save-dev sass-loader npm install --save-dev mockjs npm install --save-dev axios-mock-adapter ``` ![](https://img.kancloud.cn/1a/d6/1ad688e862409cb5761a3e5ca5e56ced_677x457.png) ![](https://img.kancloud.cn/64/e0/64e030db596e2d8620cfb79a14665e11_677x457.png) ![](https://img.kancloud.cn/9b/8e/9b8e59643de3d739cb16aeba3f3288ec_677x457.png) ![](https://img.kancloud.cn/57/66/5766cf4c994a19964f88f4746bed48f7_677x457.png) ![](https://img.kancloud.cn/a0/4c/a04cc33d8a06d30948130aa4066536ee_677x457.png) ![](https://img.kancloud.cn/63/30/6330decf88021958c1aa050af13ac9ed_677x457.png) ![](https://img.kancloud.cn/1e/8e/1e8ef6659fdacebe94e4f2e9484a9201_677x457.png) ## 三、为element-ui设定主题 进去https://elementui.github.io/theme-chalk-preview/#/zh-CN网站,选择喜欢的颜色并下载主题; ![](https://img.kancloud.cn/35/b0/35b0edd9d43f42a8cc2aa7134d44c09e_617x86.png) 把下载的主题放置目录下 src\\assets\\theme; ![](https://img.kancloud.cn/f3/13/f313dd496ef6ac11d88e75d15d41c4a2_618x164.png) ## 四、main.js程序入口 在main.js中导入“font-awesome”和“element-ui”; ``` import 'font-awesome/css/font-awesome.min.css' import ElementUI from 'element-ui' import './assets/theme/element-#004F87/index.css' Vue.use(ElementUI) ``` ## 五、App.vue文件 修改,增加一个ElementUI过渡动画组件: ``` <template> <div id="app"> <transition name="fade" mode="out-in"> <router-view></router-view> </transition> </div> </template> ``` ## 六、开发 在src目录下新建pages文件夹,并添加两个空vue文件:“Main.vue”和“Dashboard.vue”; Main.vue主体代码: ``` <template> <section> </section> </template> <script> export default {} </script> <style scoped> </style> ``` Dashboard.vue主体代码: ``` <template> <section> <el-container class="container"> <!--左边--> <el-aside :width="collapsed? '65px' : '200px' "> <el-container> <el-header> <span class="menu-button" v-if="collapsed" @click.prevent="collapsed=!collapsed"> <i class="fa fa-align-justify"></i> </span> <span v-else class="system-name">{{systemName}}</span> </el-header> <el-main> <el-menu :collapse="collapsed"> <el-submenu index="1"> <template slot="title"> <i class="el-icon-menu"></i> <span>菜单一</span> </template> <el-menu-item-group> <el-menu-item index="1-1">选项1</el-menu-item> <el-menu-item index="1-2">选项2</el-menu-item> </el-menu-item-group> </el-submenu> </el-menu> </el-main> </el-container> </el-aside> <!--内容--> <el-container> <!--页眉--> <el-header class="header"> <el-row> <el-col :span="18" class="header-title"> <span v-if="collapsed" class="system-name">{{systemName}}</span> <span v-else class="menu-button" @click.prevent="collapsed=!collapsed"> <i class="fa fa-align-justify"></i> </span> </el-col> <el-col :span="6"><span class="el-dropdown-link userinfo-inner">你好:{{userName}}</span></el-col> </el-row> </el-header> <!--中间--> <el-main class="main"> <transition name="fade" mode="out-in"> <router-view></router-view> </transition> </el-main> </el-container> </el-container> </section> </template> <script> let data = () => { return { collapsed: false, systemName: '后台管理', userName: '系统管理员' } } export default { data: data, methods: { }, mounted: function() { } } </script> <style scoped="scoped" lang="scss"> ... } </style> ``` 然后,调整路由设定: ![](https://img.kancloud.cn/10/1e/101ef74eb6d7fce5af659bff39f18005_295x405.png) ``` import Vue from 'vue' import Router from 'vue-router' Vue.use(Router) import Main from '@/pages/Main' import Dashboard from '@/pages/Dashboard' let routes = [{ path: '/', component: Main, hidden: true, children: [{ path: '/', component: Dashboard, name: '首页' }] }] const router = new Router({ routes: routes }) export default router ``` 到这里,就完成了一个简单的支持导航和页面布局的完整实例了; ![](https://img.kancloud.cn/f7/24/f72465aa1ada7f8c16d33ef67fc8bbe3_1366x736.png)