样式细节

  1. font-weight: 700; //字体粗细
  2. letter-spacing: 3px; //字与字之间的间距
  3. border-radius: 50%; //圆形

项目创建

项目创建

vue create sell
image.png

加入Element -UI

npm 安装 npm i element-ui -S
全部导入 在main.js文件中加入以下代码

  1. import ElementUI from 'element-ui'
  2. import 'element-ui/lib/theme-chalk/index.css'
  3. Vue.use(ElementUI)

创建.prettierrc文件,键入下列内容:

  1. {
  2. "semi": false,
  3. "singleQuote": true,
  4. "trailingComma": "none"
  5. }

.eslintrc.jsrules中加入

  1. 'space-before-function-paren' : 0

改造项目

1.在src目录下新建layout全局布局文件夹。
2.将 Home移动到 layout,对应修改router\index.js文件中的引用路径
3.删除 helloword.vue

测试element-ui的引入是否成功

home.vue中插入一段关于element-ui的代码 图中标签内的代码

  1. <template>
  2. <div class="home">
  3. <img alt="Vue logo" src="../assets/logo.png" />
  4. <el-row>
  5. <el-button>默认按钮</el-button>
  6. <el-button type="primary">主要按钮</el-button>
  7. <el-button type="success">成功按钮</el-button>
  8. <el-button type="info">信息按钮</el-button>
  9. <el-button type="warning">警告按钮</el-button>
  10. <el-button type="danger">危险按钮</el-button>
  11. </el-row>
  12. </div>
  13. </template>
  14. <script>
  15. export default {
  16. name: 'Home'
  17. }
  18. </script>

搭建基本结构

项目初始化

各大主流网站css初始化代码
css 初始化 创建 src\assets\css\reset.css
创建自己的样式文件 index.less

  1. html,
  2. body {
  3. height: 100%;
  4. }
  1. html, body, div, span, applet, object, iframe,
  2. h1, h2, h3, h4, h5, h6, p, blockquote, pre,
  3. a, abbr, acronym, address, big, cite, code,
  4. del, dfn, em, img, ins, kbd, q, s, samp,
  5. small, strike, strong, sub, sup, tt, var,
  6. b, u, i, center,
  7. dl, dt, dd, ol, ul, li,
  8. fieldset, form, label, legend,
  9. table, caption, tbody, tfoot, thead, tr, th, td,
  10. article, aside, canvas, details, embed,
  11. figure, figcaption, footer, header, hgroup,
  12. menu, nav, output, ruby, section, summary,
  13. time, mark, audio, video{
  14. margin: 0;
  15. padding: 0;
  16. border: 0;
  17. font-size: 100%;
  18. font: inherit;
  19. font-weight: normal;
  20. vertical-align: baseline;
  21. }
  22. /* HTML5 display-role reset for older browsers */
  23. article, aside, details, figcaption, figure,
  24. footer, header, hgroup, menu, nav, section{
  25. display: block;
  26. }
  27. ol, ul, li{
  28. list-style: none;
  29. }
  30. blockquote, q{
  31. quotes: none;
  32. }
  33. blockquote:before, blockquote:after,
  34. q:before, q:after{
  35. content: '';
  36. content: none;
  37. }
  38. table{
  39. border-collapse: collapse;
  40. border-spacing: 0;
  41. }
  42. /* custom */
  43. a{
  44. color: #7e8c8d;
  45. text-decoration: none;
  46. -webkit-backface-visibility: hidden;
  47. }
  48. ::-webkit-scrollbar{
  49. width: 5px;
  50. height: 5px;
  51. }
  52. ::-webkit-scrollbar-track-piece{
  53. background-color: rgba(0, 0, 0, 0.2);
  54. -webkit-border-radius: 6px;
  55. }
  56. ::-webkit-scrollbar-thumb:vertical{
  57. height: 5px;
  58. background-color: rgba(125, 125, 125, 0.7);
  59. -webkit-border-radius: 6px;
  60. }
  61. ::-webkit-scrollbar-thumb:horizontal{
  62. width: 5px;
  63. background-color: rgba(125, 125, 125, 0.7);
  64. -webkit-border-radius: 6px;
  65. }
  66. html, body{
  67. width: 100%;
  68. font-family: "Arial", "Microsoft YaHei", "黑体", "宋体", "微软雅黑", sans-serif;
  69. }
  70. body{
  71. line-height: 1;
  72. -webkit-text-size-adjust: none;
  73. -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  74. }
  75. html{
  76. overflow-y: scroll;
  77. }
  78. /*清除浮动*/
  79. .clearfix:before,
  80. .clearfix:after{
  81. content: " ";
  82. display: inline-block;
  83. height: 0;
  84. clear: both;
  85. visibility: hidden;
  86. }
  87. .clearfix{
  88. *zoom: 1;
  89. }
  90. /*隐藏*/
  91. .dn{
  92. display: none;
  93. }

在main.js中引入样式,注意:样式文件都放在asset里面,注意引入的顺序。

  1. import Vue from 'vue'
  2. import App from './App.vue'
  3. import router from './router'
  4. // 引入初始化css文件
  5. import './assets/css/reset.css'
  6. // 引入element-ui
  7. import ElementUI from 'element-ui'
  8. import 'element-ui/lib/theme-chalk/index.css'
  9. // 引入自己定义的主样式文件
  10. import './assets/css/index.less'
  11. // 引入字体图标文件
  12. import './assets/fonts/iconfont.css' //使用<p class="iconfont icon-renwu">123</p>
  13. Vue.use(ElementUI)
  14. Vue.config.productionTip = false
  15. new Vue({
  16. router,
  17. render: (h) => h(App)
  18. }).$mount('#app')

创建大路由和主页面

当前目录中已有的部件
layout中 Home.vue
views中 About.vue Error.vue Login.vue
并在router/index.js中设置了访问路径。

  1. import Vue from 'vue'
  2. import VueRouter from 'vue-router'
  3. import Home from '../layout/Home.vue'
  4. Vue.use(VueRouter)
  5. const routes = [
  6. {
  7. path: '/',
  8. redirect: '/home'
  9. },
  10. {
  11. path: '/home',
  12. name: 'Home',
  13. component: Home
  14. },
  15. {
  16. path: '/login',
  17. name: 'Login',
  18. component: () =>
  19. import(/* webpackChunkName: "about" */ '../views/Login.vue')
  20. },
  21. {
  22. path: '/about',
  23. name: 'About',
  24. // route level code-splitting
  25. // this generates a separate chunk (about.[hash].js) for this route
  26. // which is lazy-loaded when the route is visited.
  27. component: () =>
  28. import(/* webpackChunkName: "about" */ '../views/About.vue')
  29. },
  30. {
  31. path: '*',
  32. redict: '/404'
  33. },
  34. {
  35. path: '/404',
  36. name: 'Error',
  37. component: () =>
  38. import(/* webpackChunkName: "about" */ '../views/Error.vue')
  39. }
  40. ]
  41. const router = new VueRouter({
  42. routes
  43. })
  44. export default router

改造登录页面Login.vue

对齐弹性容器中的弹性项目

在 vue 的单文件组件中,没有办法给编译之后的盒子加样式,如果想加,那么有两种方式:
方法一,在全局的 index.less 中找到编译之后的类名或者标签,定义全局的样式。
方法二,在当前的组件中,使用 穿刺的写法。

样式使用的总结

  1. 如果是将来也需要用到的样式,那么可以声明到 index.less 全局样式中<br /> 如果只是局部生效,那么就可以使用穿刺的写法 (注意:先去观察盒子结构,以**最终编译的结果**为准)<br /> style 标签中,如果想使用less的语法,一定要加上 lang="less" 不加的话,默认是css<br /> 如果是希望当前的样式私有化,那么一定要加上 scoped 属性,不然会影响其他页面。

表单使用的介绍

  1. 数据对象、规则对象、ref (获取DOM元素)<br /> 数据对象通过 :model 绑定在表单 el-form 上,所有表单元素的 v-model 都是来源这里的数据<br /> 规则对象通过 :rules 绑定在表单 el-form 上,在所有的 el-from-item 中使用 prop 进行绑定<br /> 如果有规则,一定保证规则的属性和数据对象的属性一致<br /> ref 这个用来操作DOM,将来点击事件会使用该元素调用对应的方法<br /> 在默认的方法中,使用事件传参的方式进行调用<br />**export导出需要解构。{a,b}**

完成首页基本布局Home.vue

在Element-UI中选一个容器布局 (aseide header main footer)

  1. .el-submenu.is-opened {
  2. li {
  3. background-color: #202f3f !important;
  4. }
  5. }

给aseide 添加NavMen.vue 导航组件

复制标签包含的内容

logo处理

  1. .logo {
  2. display: flex;
  3. justify-content: center; //居中
  4. align-content: center;
  5. align-items: center;
  6. padding: 10px 0;
  7. // 添加小手
  8. cursor: pointer;
  9. // 取消双击选中
  10. -moz-user-select: none; /*火狐*/
  11. -webkit-user-select: none; /*webkit浏览器*/
  12. -ms-user-select: none; /*IE10*/
  13. -khtml-user-select: none; /*早期浏览器*/
  14. user-select: none;
  15. img {
  16. width: 50px;
  17. height: 50px;
  18. border-radius: 50%; //圆形
  19. }
  20. h3 {
  21. color: #fff;
  22. margin-left: 10px;
  23. font-weight: 700;
  24. letter-spacing: 3px; //字与字之间的间距
  25. }

css双击取消选中文字

  1. div{
  2. -moz-user-select:none;/*火狐*/
  3. -webkit-user-select:none;/*webkit浏览器*/
  4. -ms-user-select:none;/*IE10*/
  5. -khtml-user-select:none;/*早期浏览器*/
  6. user-select:none;
  7. }

折叠菜单显示

结构创建在了 el-aside 里面,目的就是将来点击标题的时候,能够控制自己和 aside 的宽度

  1. <el-aside :width="isCollapse ? '64px' : '200px'">
  2. <!-- 首页标题 -->
  3. <div class="logo" @click="isCollapse = !isCollapse">
  4. <img src="../assets/images/logo.jpg" alt="" />
  5. <h3 v-show="!isCollapse">外卖商家中心</h3>
  6. </div>
  7. <!-- 侧边栏部分 -->
  8. <NavMenu :bool="isCollapse" /> //给子组件传递参数
  9. </el-aside>
  10. <!-- 省略了在data中声明 isCollapse 为 false 的值 -->

注意在子组件中接收的方式

  1. <el-menu
  2. default-active="2"
  3. class="el-menu-vertical-demo"
  4. @open="handleOpen"
  5. @close="handleClose"
  6. background-color="#304156"
  7. text-color="#fff"
  8. active-text-color="#1989fa"
  9. :collapse="bool"
  10. :collapse-transition="false"
  11. >
  12. <script>
  13. export default {
  14. props: { //接收父组件的参数
  15. bool: {
  16. type: Boolean,
  17. default: false
  18. }
  19. }
  20. }
  21. </script>

剩下的就是美化一下样式

  1. .logo {
  2. display: flex;
  3. justify-content: center;
  4. align-items: center;
  5. padding: 10px 0;
  6. // 取消文字选择
  7. -moz-user-select: none; /*火狐*/
  8. -webkit-user-select: none; /*webkit浏览器*/
  9. -ms-user-select: none; /*IE10*/
  10. -khtml-user-select: none; /*早期浏览器*/
  11. user-select: none;
  12. // 添加小手
  13. cursor: pointer;
  14. img {
  15. width: 40px;
  16. height: 40px;
  17. border-radius: 50%;
  18. }
  19. h3 {
  20. color: #fff;
  21. margin-left: 10px;
  22. letter-spacing: 3px;
  23. }
  24. }

5.1 header 部分的布局

  1. header 的部分创建,还是新建到 components 中去,然后以子组件的方式引入到 Home

5.2 Main 页面的创建

  1. 1 2 3 测试
  1. - Dashboard.vue 后台首页
  2. - Order.vue 订单管理
  3. - Product 商品管理
  4. - Index.vue 主路由文件(二级)
  5. - ProList.vue 商品列表
  6. - ProAdd.vue 商品添加
  7. - ProCate.vue 商品分类
  8. - Shop.vue 店铺管理
  9. - Account 账号管理
  10. - Index.vue 主路由文件(二级)
  11. - AccountList.vue 账号列表
  12. - AccountAdd.vue 添加账号
  13. - ResetPwd.vue 密码重置
  14. - SellCount 销售统计
  15. - Index.vue 主路由文件(二级)
  16. - GoodsCount.vue 商品统计
  17. - OrdersCount.vue 订单统计

创建上述页面,并配置路由的配置

  1. import Vue from 'vue'
  2. import VueRouter from 'vue-router'
  3. import Home from '../layout/Home.vue'
  4. Vue.use(VueRouter)
  5. const routes = [
  6. {
  7. path: '/',
  8. redirect: '/home'
  9. },
  10. {
  11. path: '/home',
  12. name: 'Home',
  13. component: Home,
  14. redirect: '/dashboard',
  15. // 配置二级路由
  16. children: [
  17. {
  18. path: '/dashboard',
  19. component: () =>
  20. import(/* webpackChunkName: "about" */ '../views/Dashboard/index.vue')
  21. },
  22. {
  23. path: '/pro',
  24. component: () =>
  25. import(/* webpackChunkName: "about" */ '../views/Product/index.vue'),
  26. children: [
  27. {
  28. path: '/pro/List', // 二级路由需加一级路由地址
  29. component: () =>
  30. import(
  31. /* webpackChunkName: "about" */ '../views/Product/proList.vue'
  32. )
  33. },
  34. {
  35. path: '/pro/add',
  36. component: () =>
  37. import(
  38. /* webpackChunkName: "about" */ '../views/Product/ProAdd.vue'
  39. )
  40. },
  41. {
  42. path: '/pro/cate',
  43. component: () =>
  44. import(
  45. /* webpackChunkName: "about" */ '../views/Product/ProCate.vue'
  46. )
  47. }
  48. ]
  49. },
  50. {
  51. path: '/shop',
  52. component: () =>
  53. import(/* webpackChunkName: "about" */ '../views/Shop/index.vue')
  54. }
  55. ]
  56. },
  57. {
  58. path: '/login',
  59. name: 'Login',
  60. component: () =>
  61. import(/* webpackChunkName: "about" */ '../views/Login.vue')
  62. },
  63. {
  64. path: '/about',
  65. name: 'About',
  66. // route level code-splitting
  67. // this generates a separate chunk (about.[hash].js) for this route
  68. // which is lazy-loaded when the route is visited.
  69. component: () =>
  70. import(/* webpackChunkName: "about" */ '../views/About.vue')
  71. },
  72. {
  73. path: '*',
  74. redirect: '/404'
  75. },
  76. {
  77. path: '/404',
  78. name: 'Error',
  79. component: () =>
  80. import(/* webpackChunkName: "about" */ '../views/Error.vue')
  81. }
  82. ]
  83. const router = new VueRouter({
  84. routes
  85. })
  86. export default router

完成导航
NavMenu 导航菜单 添加:router="true",替换index = “路由路径” 。

  1. <el-menu
  2. default-active="/dashboard" // 默认展示
  3. :default-active="$route.path"
  4. class="el-menu-vertical-demo"
  5. @open="handleOpen"
  6. @close="handleClose"
  7. background-color="#304156"
  8. text-color="#fff"
  9. active-text-color="#1989fa"
  10. :collapse="bool"
  11. :collapse-transition="false"
  12. :router="true"
  13. >