码迷,mamicode.com
首页 > 其他好文 > 详细

结算系统时候用到的左侧递归 导航条功能

时间:2018-12-01 17:06:19      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:res   bfc   hid   length   style   exp   show   temp   scrollbar   

<template>
  <el-scrollbar wrapClass="scrollbar-wrapper">
    <el-menu
      mode="vertical"
      :show-timeout="200"
      :default-active="$route.path"
      :collapse="isCollapse"
      background-color="#304156"
      text-color="#bfcbd9"
      active-text-color="#409EFF"
    >
      <sidebar-item v-for="route in permission_routers" :key="route.name" :item="route" :base-path="route.path"></sidebar-item>
    </el-menu>
  </el-scrollbar>
</template>

<script>
import { mapGetters } from ‘vuex‘
import SidebarItem from ‘./SidebarItem‘
import routers from ‘@/router/index‘
/* Layout */
// import Layout from ‘@/pages/layout/Layout‘
export default {
  data() {
    return {
      permission_routers: undefined,
      tmpArr: [],
      apiArr: JSON.parse(localStorage.getItem(‘SET_ROUTERS‘))
    }
  },
  mounted() {
    // console.log(this.apiArr)
    this.loop(this.apiArr)
    // console.log(this.tmpArr)
    this.loopRoutes(routers.options.routes)
    this.permission_routers = routers.options.routes
  },
  methods: {
    checkIsHidden: function(opt) {
      if (this.apiArr) {
        if (this.tmpArr.indexOf(opt) >= 0) {
          return false
        } else {
          return true
        }
      }
    },
    loop: function(arr) {
      for (var i = 0; i < arr.length; i++) {
        this.tmpArr.push(arr[i].resName)
        if (arr[i].hasSubResource === true) {
          this.loop(arr[i].subResources)
        }
      }
    },
    loopRoutes: function(arrRoutes) {
      var _this = this
      for (var i = 0; i < arrRoutes.length; i++) {
        // console.log(arrRoutes[i])
        if (arrRoutes[i].name) {
          // 开启关闭权限
          arrRoutes[i].hidden = _this.checkIsHidden(arrRoutes[i].meta.title)
          // arrRoutes[i].hidden = false
          if (arrRoutes[i].children) {
            _this.loopRoutes(arrRoutes[i].children)
          }
        }
      }
    }
  },
  components: { SidebarItem },
  computed: {
    ...mapGetters([
      // ‘permission_routers‘,
      ‘sidebar‘
    ]),
    isCollapse() {
      return !this.sidebar.opened
    }
  }
}
</script>

 

结算系统时候用到的左侧递归 导航条功能

标签:res   bfc   hid   length   style   exp   show   temp   scrollbar   

原文地址:https://www.cnblogs.com/suanmei/p/10049848.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!