Vue自定义组件

如果你不相信努力和时光,那么成果就会是第一个选择辜负你的。不要去否定你自己的过去,也不要用你的过去牵扯你现在的努力和对未来的展望。不是因为拥有希望你才去努力,而是去努力了,你才有可能看到希望的光芒。Vue自定义组件,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com,来源:原文

1.组件:  huihuiItem.vue

<!--
-->
<template>
  <div class="box">
    <!--            系统首页-->
    <el-menu-item :index="item.menuPath" v-if="item.menuType===1">
      <i :class="item.menuIcon"></i>
      <span slot="title">{{ item.menuTitle }}</span>
    </el-menu-item>

    <!--            商品相关-->
    <el-submenu :index="item.menuPath" v-if="item.menuType===0">
      <template slot="title">
        <i :class="item.menuIcon"></i>
        <span slot="title">{{ item.menuTitle }}</span>
      </template>
      <huihui-item v-for="(item,index) in item.children" :key="index" :item="item"/>
    </el-submenu>




  </div>

</template>

<script>
export default {
  name: "huihuiItem",
  props: ['item']
}
</script>

<style scoped>

</style>

2. 动态菜单使用: 主 index.vue

<template>
  <!--主页-->
  <div class="main-wrapper">
    <el-container>

      <!--      侧边栏-->
      <el-aside width="200px">
        <!--        logo部分-->
        <div class="aside-log-wrapper">
          <img src="@/assets/photo.png" alt=""/>
          <span>瞎写CRM系统</span>
        </div>
        <!--        菜单部分-->
        <!--        设置滚动条-->
        <el-scrollbar>
          <el-menu default-active="2" class="aside-menu-wrapper" router>
<!--            使用自定义组件 实现动态菜单功能-->
            <huihui-item v-for="(item,index) in menuList" :key="index" :item="item"/>
            
          </el-menu>
        </el-scrollbar>

      </el-aside>

      <el-container>
        <!--        头-->
        <el-header><h3>瞎写CRM系统-不是认真的!</h3>

        </el-header>
        <!--        主体-->
        <el-main>
          <div class="main-box">

            <router-view/>
          </div>
        </el-main>
      </el-container>
    </el-container>

  </div>
</template>

<script>
//import auth from "@/utils/auth";
import huihuiItem from "@/components/huihuiItem";

export default {
  name: "index",
  components: {huihuiItem},
  created() {
    //this.menuList = auth.getMenuList();
    this.menuList = JSON.parse(localStorage.getItem("menuList"));


  },
  data() {
    return {
      menuList: [],
    }
  },
  methods: {}
}
</script>

<style scoped lang="scss">
/*设置满屏*/
.main-wrapper {
  width: 100%;
  height: 100%;
}

/*头部*/
.el-header {
  background-color: #B3C0D1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

/*侧边栏*/
.el-aside {
  background-color: #ffffff;
  color: #333;

  /*logo*/
  .aside-log-wrapper {
    text-align: center;
    background-color: #4c8df3;
    line-height: 60px;
    /*去除logo和头部不对齐*/
    height: 60px;

    img {
      width: 50px;
      height: 50px;
      border-radius: 50%;
      /*居中对齐*/
      vertical-align: middle;
      margin-right: 8px;
    }

    span {
      font-weight: 600;
      font-family: 华文楷体, serif;
    }
  }

  /*导航栏*/
  .aside-menu-wrapper {
    font-family: 微软雅黑, serif;
  }

  .el-scrollbar {
    height: calc(100% - 60px);
  }

}

/*主体*/
.el-main {
  background-color: #E9EEF3;
  color: #333;
  padding: 5px 0 0 5px;

  .main-box {
    width: 100%;
    height: 100%;
    background-color: #fff;
    padding: 15px 0 0 15px;
    /*清除主体下面滚动条*/
    box-sizing: border-box;
  }
}

.el-container {
  height: 100%;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
</style>

 

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/192892.html

(0)
飞熊的头像飞熊bm

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!