• SPA项目开发之首页导航+左侧菜单


    目录

    一、mockjs的使用

     二、总线

    三、退出账户


    一、mockjs的使用

    步骤:

    1.安装mockjs依赖 ;npm install mockjs -D(d:仅开发中使用)

    login.vue

    1. <template>
    2. <div class="login-wrap">
    3. <el-row>
    4. <el-col :span="24">
    5. <div style="text-align: center" class="grid-content bg-purple-dark"><h3>用户登录</h3>
    6. </div></el-col>
    7. </el-row>
    8. <el-form :model="ruleForm" status-icon label-width="100px" class="demo-ruleForm login-container">
    9. <el-form-item label="用户名" prop="uname">
    10. <el-input type="text" v-model="ruleForm.uname" autocomplete="off"></el-input>
    11. </el-form-item>
    12. <el-form-item label="密码" prop="pwd">
    13. <el-input type="password" v-model="ruleForm.pwd" autocomplete="off"></el-input>
    14. </el-form-item>
    15. <el-form-item>
    16. <el-row>
    17. <el-col :span="24">
    18. <div style="text-align: center" class="grid-content bg-purple-dark">
    19. <el-button style="width: 100%" type="primary" @click="submitForm">提交</el-button>
    20. </div>
    21. </el-col>
    22. </el-row>
    23. </el-form-item>
    24. <el-form-item>
    25. <el-row>
    26. <el-col :span="12">
    27. <div style="text-align: center" class="grid-content bg-purple-dark">
    28. <el-link type="success" @click="toReg">用户注册</el-link>
    29. </div>
    30. </el-col>
    31. <el-col :span="12">
    32. <div style="text-align: center" class="grid-content bg-purple-dark">
    33. <el-link type="warning">忘记密码</el-link>
    34. </div>
    35. </el-col>
    36. </el-row>
    37. </el-form-item>
    38. </el-form>
    39. </div>
    40. </template>
    41. <script>
    42. import qs from 'qs'
    43. export default {
    44. name: 'Login',
    45. data () {
    46. return {
    47. ruleForm: {}
    48. }
    49. },
    50. methods:{
    51. submitForm(){
    52. //this.axios找到的是 /api/http.js文件
    53. //xios.urls——>this.axios/urls找到了 /api/action.js
    54. //action.js是一个JSON对象,那么就可以取到请求的值
    55. let url = this.axios.urls.SYSTEM_USER_DOLOGIN;
    56. // let url="http://localhost:8080/T216_SSH/vue/treeNodeAction.action";
    57. // {uname:'zs',pwd:'123'}
    58. //this指的是vue实例
    59. this.axios.post(url,this.ruleForm)
    60. .then(resp => {//代表成功 箭头函数 jdk8的语法
    61. console.log(resp);
    62. if(resp.data.code == 1){
    63. //this指的是http.js
    64. this.$message({
    65. message: resp.data.msg,
    66. type: 'success'
    67. });
    68. this.$router.push({path:'/AppMain'});
    69. }else if(resp.data.code == 0) {
    70. //this指的是http.js
    71. this.$message.error(resp.data.msg);
    72. }
    73. }).catch(function (){//代表失败
    74. });
    75. },
    76. resetForm(){
    77. },
    78. toReg(){
    79. this.$router.push({path:'/Reg'})
    80. }
    81. }
    82. }
    83. </script>
    84. <style scoped>
    85. .login-wrap {
    86. box-sizing: border-box;
    87. width: 100%;
    88. height: 100%;
    89. padding-top: 10%;
    90. background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+Cjxzdmcgd2lkdGg9IjEzNjFweCIgaGVpZ2h0PSI2MDlweCIgdmlld0JveD0iMCAwIDEzNjEgNjA5IiB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPgogICAgPCEtLSBHZW5lcmF0b3I6IFNrZXRjaCA0Ni4yICg0NDQ5NikgLSBodHRwOi8vd3d3LmJvaGVtaWFuY29kaW5nLmNvbS9za2V0Y2ggLS0+CiAgICA8dGl0bGU+R3JvdXAgMjE8L3RpdGxlPgogICAgPGRlc2M+Q3JlYXRlZCB3aXRoIFNrZXRjaC48L2Rlc2M+CiAgICA8ZGVmcz48L2RlZnM+CiAgICA8ZyBpZD0iQW50LURlc2lnbi1Qcm8tMy4wIiBzdHJva2U9Im5vbmUiIHN0cm9rZS13aWR0aD0iMSIgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIj4KICAgICAgICA8ZyBpZD0i6LS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sZSBpZD0iT3ZhbC01LUNvcHktMiIgZmlsbC1vcGFjaXR5PSIwLjYiIGZpbGw9IiNEMURFRUQiIGN4PSI4Ljc1IiBjeT0iMzMuMjUiIHI9IjguNzUiPjwvY2lyY2xlPgogICAgICAgICAgICAgICAgICAgIDxjaXJjbGUgaWQ9Ik92YWwtNS1Db3B5LTQiIGZpbGwtb3BhY2l0eT0iMC42IiBmaWxsPSIjRDFERUVEIiBjeD0iMjQzLjgzMzMzMyIgY3k9IjMwLjMzMzMzMzMiIHI9IjUuODMzMzMzMzMiPjwvY2lyY2xlPgogICAgICAgICAgICAgICAgICAgIDxjaXJjbGUgaWQ9Ik92YWwtNS1Db3B5LTUiIGZpbGw9IiNFMEI0QjciIGN4PSIxNzUuNTgzMzMzIiBjeT0iMjMyLjc1IiByPSI1LjI1Ij48L2NpcmNsZT4KICAgICAgICAgICAgICAgIDwvZz4KICAgICAgICAgICAgPC9nPgogICAgICAgIDwvZz4KICAgIDwvZz4KPC9zdmc+);
    91. /* background-color: #112346; */
    92. background-repeat: no-repeat;
    93. background-position: center right;
    94. background-size: 100%;
    95. }
    96. .login-container {
    97. border-radius: 10px;
    98. margin: 0px auto;
    99. width: 350px;
    100. padding: 30px 35px 15px 35px;
    101. background: #fff;
    102. border: 1px solid #eaeaea;
    103. text-align: left;
    104. box-shadow: 0 0 20px 2px rgba(0, 0, 0, 0.1);
    105. }
    106. .title {
    107. margin: 0px auto 40px auto;
    108. text-align: center;
    109. color: #505458;
    110. }
    111. </style>

    2.配置开发环境及生产环境

    prod.env.js

    1. 'use strict'
    2. module.exports = {
    3. NODE_ENV: '"production"',
    4. MOCK:'false'
    5. }

     dev.env.js

    1. 'use strict'
    2. const merge = require('webpack-merge')
    3. const prodEnv = require('./prod.env')
    4. module.exports = merge(prodEnv, {
    5. NODE_ENV: '"development"',
    6. MOCK:'true'
    7. })

    3.导入公共模块及mockjs全局设置

    在src目录下创建mock目录,定义mock主文件index.js,并在该文件中定义拦截路由配置,

    界面效果图:


     二、总线

     vue Bus总线:将一个空的Vue实例放到根组件下,所有的子组件都能调用

     main.js
            new Vue({
        el: '#app',
        router,
        components: {
            App
        },
        template: '',
        data: {
            //自定义的事件总线对象,用于父子组件的通信
            Bus: new Vue()
        }
             })

    topNav.vue

    1. <template>
    2. <!-- <el-menu :default-active="activeIndex2" class="el-menu-demo" mode="horizontal" @select="handleSelect" background-color="#545c64"
    3. text-color="#fff" active-text-color="#ffd04b">
    4. <el-menu-item index="1">处理中心</el-menu-item>
    5. <el-submenu index="2">
    6. <template slot="title">我的工作台</template>
    7. <el-menu-item index="2-1">选项1</el-menu-item>
    8. <el-menu-item index="2-2">选项2</el-menu-item>
    9. <el-menu-item index="2-3">选项3</el-menu-item>
    10. <el-submenu index="2-4">
    11. <template slot="title">选项4</template>
    12. <el-menu-item index="2-4-1">选项1</el-menu-item>
    13. <el-menu-item index="2-4-2">选项2</el-menu-item>
    14. <el-menu-item index="2-4-3">选项3</el-menu-item>
    15. </el-submenu>
    16. </el-submenu>
    17. <el-menu-item index="3" disabled>消息中心</el-menu-item>
    18. <el-menu-item index="4"><a href="https://www.ele.me" target="_blank">订单管理</a></el-menu-item>
    19. </el-menu> -->
    20. <el-menu class="el-menu-demo" mode="horizontal" background-color="#334157" text-color="#fff" active-text-color="#fff">
    21. <el-button class="buttonimg">
    22. <img class="showimg" :src="collapsed?imgshow:imgsq" @click="doToggle()">
    23. </el-button>
    24. <el-submenu index="2" class="submenu">
    25. <template slot="title">超级管理员</template>
    26. <el-menu-item index="2-1">设置</el-menu-item>
    27. <el-menu-item index="2-2">个人中心</el-menu-item>
    28. <el-menu-item @click="exit()" index="2-3">退出</el-menu-item>
    29. </el-submenu>
    30. </el-menu>
    31. </template>
    32. <script>
    33. export default {
    34. data(){
    35. return{
    36. collapsed:false,
    37. imgshow:require('@/assets/img/show.png'),
    38. imgsq:require('@/assets/img/sq.png')
    39. }
    40. },
    41. methods:{
    42. doToggle(){
    43. this.collapsed=!this.collapsed;
    44. this.$root.Bus.$emit("collapsed-aside", this.collapsed);
    45. }
    46. }
    47. }
    48. </script>
    49. <style scoped>
    50. .el-menu-vertical-demo:not(.el-menu--collapse) {
    51. border: none;
    52. }
    53. .submenu {
    54. float: right;
    55. }
    56. .buttonimg {
    57. height: 60px;
    58. background-color: transparent;
    59. border: none;
    60. }
    61. .showimg {
    62. width: 26px;
    63. height: 26px;
    64. position: absolute;
    65. top: 17px;
    66. left: 17px;
    67. }
    68. .showimg:active {
    69. border: none;
    70. }
    71. </style>

    leftNAv.vue

    1. <template>
    2. <el-menu default-active="2" class="el-menu-vertical-demo" background-color="#334157"
    3. text-color="#fff" active-text-color="#ffd04b" :collapse="collapsed" >
    4. <!-- <el-menu default-active="2" :collapse="collapsed" collapse-transition router :default-active="$route.path" unique-opened class="el-menu-vertical-demo" background-color="#334157" text-color="#fff" active-text-color="#ffd04b"> -->
    5. <div class="logobox">
    6. <img class="logoimg" src="../assets/img/logo.png" alt="">
    7. </div>
    8. <el-submenu index="1">
    9. <template slot="title">
    10. <i class="el-icon-location"></i>
    11. <span>导航一</span>
    12. </template>
    13. <el-menu-item-group>
    14. <template slot="title">分组一</template>
    15. <el-menu-item index="1-1">选项1</el-menu-item>
    16. <el-menu-item index="1-2">选项2</el-menu-item>
    17. </el-menu-item-group>
    18. <el-menu-item-group title="分组2">
    19. <el-menu-item index="1-3">选项3</el-menu-item>
    20. </el-menu-item-group>
    21. <el-submenu index="1-4">
    22. <template slot="title">选项4</template>
    23. <el-menu-item index="1-4-1">选项1</el-menu-item>
    24. </el-submenu>
    25. </el-submenu>
    26. <el-menu-item index="2">
    27. <i class="el-icon-menu"></i>
    28. <span slot="title">导航二</span>
    29. </el-menu-item>
    30. <el-menu-item index="3" disabled>
    31. <i class="el-icon-document"></i>
    32. <span slot="title">导航三</span>
    33. </el-menu-item>
    34. <el-menu-item index="4">
    35. <i class="el-icon-setting"></i>
    36. <span slot="title">导航四</span>
    37. </el-menu-item>
    38. </el-menu>
    39. </template>
    40. <script>
    41. export default {
    42. data(){
    43. return{
    44. collapsed:false
    45. }
    46. },
    47. created() {
    48. this.$root.Bus.$on("collapsed-aside", (v) =>{
    49. this.collapsed=v;
    50. });
    51. }
    52. }
    53. </script>
    54. <style>
    55. .el-menu-vertical-demo:not(.el-menu--collapse) {
    56. width: 240px;
    57. min-height: 400px;
    58. }
    59. .el-menu-vertical-demo:not(.el-menu--collapse) {
    60. border: none;
    61. text-align: left;
    62. }
    63. .el-menu-item-group__title {
    64. padding: 0px;
    65. }
    66. .el-menu-bg {
    67. background-color: #1f2d3d !important;
    68. }
    69. .el-menu {
    70. border: none;
    71. }
    72. .logobox {
    73. height: 40px;
    74. line-height: 40px;
    75. color: #9d9d9d;
    76. font-size: 20px;
    77. text-align: center;
    78. padding: 20px 0px;
    79. }
    80. .logoimg {
    81. height: 40px;
    82. }
    83. </style>

     appNav.vue

    1. <template>
    2. <el-container class="main-container">
    3. <el-aside v-bind:class="asideClass">
    4. <LeftNav></LeftNav>
    5. </el-aside>
    6. <el-container>
    7. <el-header class="main-header">
    8. <TopNav></TopNav>
    9. </el-header>
    10. <el-main class="main-center">Main</el-main>
    11. </el-container>
    12. </el-container>
    13. </template>
    14. <script>
    15. // 导入组件
    16. import TopNav from '@/components/TopNav.vue'
    17. import LeftNav from '@/components/LeftNav.vue'
    18. // 导出模块
    19. export default {
    20. data(){
    21. return{
    22. asideClass:'main-aside'
    23. }
    24. },
    25. components:{
    26. TopNav,LeftNav //注册
    27. },
    28. created() {
    29. this.$root.Bus.$on("collapsed-aside", (v) =>{
    30. this.asideClass=v ?'main-aside-collapsed' :'main-aside' ;
    31. });
    32. }
    33. };
    34. </script>
    35. <style scoped>
    36. .main-container {
    37. height: 100%;
    38. width: 100%;
    39. box-sizing: border-box;
    40. }
    41. .main-aside-collapsed {
    42. /* 在CSS中,通过对某一样式声明! important ,可以更改默认的CSS样式优先级规则,使该条样式属性声明具有最高优先级 */
    43. width: 64px !important;
    44. height: 100%;
    45. background-color: #334157;
    46. margin: 0px;
    47. }
    48. .main-aside {
    49. width: 240px !important;
    50. height: 100%;
    51. background-color: #334157;
    52. margin: 0px;
    53. }
    54. .main-header,
    55. .main-center {
    56. padding: 0px;
    57. border-left: 2px solid #333;
    58. }
    59. </style>

    设置路由index.js

    1. import Vue from 'vue'
    2. import Router from 'vue-router'
    3. import HelloWorld from "@/components/HelloWorld";
    4. import Login from "@/views/Login";
    5. import Reg from "@/views/Reg";
    6. import AppMain from '@/components/AppMain';
    7. import LeftNav from '@/components/LeftNav';
    8. import TopNav from '@/components/TopNav';
    9. Vue.use(Router)
    10. export default new Router({
    11. routes: [
    12. {
    13. path: '/',
    14. name: 'Login',
    15. component: Login
    16. },
    17. {
    18. path: '/Login',
    19. name: 'Login',
    20. component: Login
    21. },
    22. {
    23. path: '/Reg',
    24. name: 'Reg',
    25. component: Reg
    26. },
    27. {
    28. path: '/AppMain',
    29. name: 'AppMain',
    30. component: AppMain,
    31. children:[
    32. {
    33. path: '/LeftNav',
    34. name: 'LeftNav',
    35. component: LeftNav
    36. },
    37. {
    38. path: '/TopNav',
    39. name: 'TopNav',
    40. component: TopNav
    41. }
    42. ]
    43. }
    44. ]
    45. })

    main.js

    1. // The Vue build version to load with the `import` command
    2. // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
    3. import Vue from 'vue'
    4. //引入mockjs,在开发环境下
    5. process.env.mock && require('@/mock')
    6. import ElementUI from 'element-ui' // 新添加 1
    7. import 'element-ui/lib/theme-chalk/index.css' // 新添加 2 ,避免后期打包样式不同,要放在import App from './App'; 之前
    8. import App from './App'
    9. import router from './router'
    10. import axios from '@/api/http' //#vue项目对axios的全局配置
    11. // import axios from 'axios'
    12. import VueAxios from 'vue-axios'
    13. Vue.use(VueAxios,axios)
    14. Vue.use(ElementUI) // 新添加 3
    15. Vue.config.productionTip = false
    16. /* eslint-disable no-new */
    17. new Vue({
    18. el: '#app',
    19. data(){
    20. return {
    21. Bus:new Vue({
    22. })
    23. }
    24. }
    25. router,//挂载边界
    26. components: { App },
    27. template: ''
    28. })

    图标效果图:

     

    三、退出账户

     topNav.vue

    1. <script>
    2. export default {
    3. data(){
    4. return{
    5. collapsed:false,
    6. imgshow:require('@/assets/img/show.png'),
    7. imgsq:require('@/assets/img/sq.png')
    8. }
    9. },
    10. methods:{
    11. doToggle(){
    12. this.collapsed=!this.collapsed;
    13. this.$root.Bus.$emit("collapsed-aside", this.collapsed);
    14. },
    15. exit(){
    16. this.$router.push({path:'/Login'});//退出
    17. }
    18. }
    19. }
    20. script>

     退出效果图:


  • 相关阅读:
    PowerPC平台移植RTL8822BU
    5. 【线索二叉树】的由来、基本概念、结构体定义、三种遍历线索化、线索二叉树找前驱/后继
    如何利用 RPA 实现自动化获客?
    IOC容器bean管理---注解方式
    联邦学习--记录
    【PPT技巧】如何将多张幻灯片打印在一张纸上?
    【linux】[OOM]now anon-rss:0kB, file-rss:0kB, shmem-rss:280kB
    wpf的GridSplitter使用
    ERP系统选型需谨慎
    MATLAB从0开始搭建简单的GUI界面
  • 原文地址:https://blog.csdn.net/qq_66924116/article/details/126808133