【vue】el-menu菜单切换页面示例

news/2024/7/9 23:59:27 标签: vue

1.示例图片

在这里插入图片描述

2.代码结构

在这里插入图片描述

3.main.js

主要代码为import router from ‘./router’,并且在new Vue中加入router

import Vue from 'vue'
import App from './App'
import router from './router'
import Element from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import axios from 'axios'

Vue.config.productionTip = false
Vue.use(Element)
Vue.use(axios)
Vue.prototype.$axios = axios

new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})

4.router/index.js

import Vue from 'vue'
import Router from 'vue-router'
//主页面
import mainPage from '@/components/views/main/mainPage'

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      name: 'mainPage',
      component: mainPage,
      children: [
        {
          path: '/system/role',
          component: () => import('../components/views/system/role.vue'),
          name: '角色管理',
        },
        {
          path: '/system/authority',
          component: () => import('../components/views/system/authority.vue'),
          name: '权限管理'
        },
        {
          path: '/system/user',
          component: () => import('../components/views/system/user.vue'),
          name: '用户管理'
        }
      ]
    }
  ]
})

vue_64">5.mainPage.vue

<template>
  <el-container style="height:calc(100%);">
    <el-aside width="200px;height:calc(100%)" class="aside">
      <mainLeft style="width:200px;hegith:100%;"></mainLeft>
    </el-aside>
    <el-main><router-view></router-view></el-main>
  </el-container>
</template>
<script>
import mainLeft from '@/components/views/main/mainLeft'

export default {
  name: "mainPage",
  components:{mainLeft},
  data() {
    return {
      screenWidth: document.documentElement.clientWidth,     // 屏幕宽
      screeHeight: document.documentElement.clientHeight,    // 屏幕高
      topHeight: document.documentElement.clientHeight*0.3,

    };
  },
  methods: {
    getHeight(){
      console.log(document.body.clientHeight);
      return document.body.clientHeight;
    },
    
  }
};
</script>

<style lang="scss" scoped>
  .el-header{
    padding:0px;
  }
  .aside{

  }
</style>

vue_107">6.mainLeft.vue

<template>
  <div>
    <el-menu
      :default-active="this.$router.path"
      text-color="#409eff"
      class="el-menu-vertical-demo"
      unique-opened 
      router
      @open="handleOpen"
      @close="handleClose"
      :collapse="isCollapse"
    >
      <el-submenu index="1">
        <template slot="title">
          <i class="el-icon-setting"></i>
          <span slot="title">系统设置</span>
        </template>
        <el-menu-item index="/system/role">
          <i class="el-icon-user"></i>
          <span slot="title">角色管理</span>
        </el-menu-item>
        <el-menu-item index="/system/authority">
          <i class="el-icon-key"></i>
          <span slot="title">权限管理</span>
        </el-menu-item>
        <el-menu-item index="/system/user">
          <i class="el-icon-user-solid"></i>
          <span slot="title">用户管理</span>
        </el-menu-item>
      </el-submenu>
    </el-menu>
  </div>
</template>
<script>
export default {
  name: "mainLeft",

  data() {
    return {
      isCollapse: false,
    };
  },
  methods: {
    handleOpen() {
      
    }
  },
};
</script>
<style lang="scss" scoped>
.el-menu-item {
  color: #409eff;
}
/deep/ .el-submenu__title {
  color: #409eff;
}
.el-submenu{
  background: #f4f4f5;
}
.el-menu-item{
  border-bottom-width: 1px;
  border-bottom-style: solid;
}
/deep/ .el-submenu__title{
  border-bottom-width: 1px;
  border-bottom-style: solid;
}

</style>

vue_179">7.authority.vue

<template>
  <div class="app-container pull-height">
    <basic-container>
      权限管理
    </basic-container>
  </div>
</template>
<script>

export default {
  name: "authority",
  data() {
    return {
    } 
  },
  methods: {
  },
};
</script>
<style lang="scss" scoped>
</style>

vue_203">8.role.vue

<template>
  <div class="app-container pull-height">
    <basic-container>
      角色管理
    </basic-container>
  </div>
</template>
<script>

export default {
  name: "role",
  data() {
    return {
    } 
  },
  methods: {
  },
};
</script>
<style lang="scss" scoped>
</style>

vue_227">9.user.vue

<template>
  <div class="app-container pull-height">
    <basic-container>
      用户管理
    </basic-container>
  </div>
</template>
<script>

export default {
  name: "user",
  data() {
    return {
    } 
  },
  methods: {
  },
};
</script>
<style lang="scss" scoped>

</style>


http://www.niftyadmin.cn/n/903280.html

相关文章

【java】json字符串转json文件

代码示例 public static boolean createJsonFile(String jsonString, String filePath, String fileName) {// 标记文件生成是否成功boolean flag true;// 拼接文件完整路径String fullPath filePath File.separator fileName ".json";// 生成json格式文件try …

【java】zip解压缩示例

1.代码示例 import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import java.util.LinkedList; import java.util.stream.Collectors; import java.util.z…

【java】Mybatis-Plus控制sql语句打印

配置修改 mybatis-plus:configuration:log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

【vue】avue-crud表格树示例

1.效果图 2.前端代码 <template><div class"app-container pull-height"><el-form inline ref"searchForm" v-model"searchForm"><el-form-item label"菜单名称&#xff1a;"><el-input size"small&…

【vue】el-dropdown el-date-picker el-popover不追加到body

<!--:append-to-body"false" el-date-picker el-popover也可使用--> <el-dropdown v-if"editEnable" ><el-button icon"el-icon-plus"></el-button><el-dropdown-menu slot"dropdown" :append-to-body&qu…

【idea】idea2020.1找不到符号

1.说明 1.看了网上一堆&#xff0c;有mvn idea:idea的&#xff0c;有改回默认maven的&#xff0c;有清除缓存的&#xff0c;比比叨一堆&#xff0c;头都痛&#xff0c;我的是这么解决的&#xff0c;看截图。 2.截图 下面这个图可以用默认的&#xff0c;我这用自己的maven库

【vue】zip下载

1.前端 <template><el-button size"medium" click"handleDownload()">下载</el-button> </template><script> import { downloadZip} from ./api export default{name: test,data() {return {}},methods: {handleDownl…

【js】vue跳出for循环

1.使用array.some() //some()当内部return true时跳出整个循环&#xff1a; var array [1,2,3,4,5]; var num 3; array.some(function(data){if(data num) {return true;}console.log(data); });2.使用array.every() //every()当内部return false时跳出整个循环 var array…