elment-ui的侧边栏 开关及窗口联动

js 复制代码
<template>
  <div class="asders">
    <el-aside width="200px">
      <div class="boxbody">
        <div>源码外卖</div>
        <el-switch v-model="isCollapse" :active-value="true" :inactive-value="false"></el-switch>
      </div>

      <el-menu
        :collapse="isCollapse"
        router
        unique-opened
        :default-active="$router.path"
        class="el-menu-vertical-demo"
        background-color="rgba(220,38,38,0.2)"
        text-color="#fff"
        active-text-color="#ffd04b"
      >
        <el-menu-item index="/last">
          <i class="el-icon-menu"></i>
          <span slot="title">后台首页</span>
        </el-menu-item>

        <el-menu-item index="/order">
          <i class="el-icon-menu"></i>
          <span slot="title">订单管理</span>
        </el-menu-item>

        <el-submenu index="/goods">
          <template slot="title">
            <i class="el-icon-location"></i>
            <span>商品管理</span>
          </template>
          <el-menu-item-group>
            <el-menu-item index="/goods/list">商品列表</el-menu-item>
            <el-menu-item index="/goods/add">商品添加</el-menu-item>
            <el-menu-item index="/goods/index">商品分类</el-menu-item>
          </el-menu-item-group>
        </el-submenu>

        <el-menu-item index="/shop">
          <i class="el-icon-menu"></i>
          <span slot="title">店铺管理</span>
        </el-menu-item>

        <el-submenu index="/account">
          <template slot="title">
            <i class="el-icon-location"></i>
            <span>账号管理</span>
          </template>
          <el-menu-item-group>
            <el-menu-item index="/account/list">账号列表</el-menu-item>
            <el-menu-item index="/account/add">添加账号</el-menu-item>
            <el-menu-item index="/account/index">修改密码</el-menu-item>
          </el-menu-item-group>
        </el-submenu>

        <el-submenu index="/sale">
          <template slot="title">
            <i class="el-icon-location"></i>
            <span>销售统计</span>
          </template>
          <el-menu-item-group>
            <el-menu-item index="/sale/goods">商品统计</el-menu-item>
            <el-menu-item index="/sale/index">销售统计</el-menu-item>
          </el-menu-item-group>
        </el-submenu>
      </el-menu>
    </el-aside>
  </div>
</template>

<script>
export default {
  data() {
    return {
      isCollapse: false
    };
  },
  methods: {
    change() {
      this.isCollapse = !this.isCollapse;
    },
    handleResize() {
      console.log(document.body.offsetWidth);
      if (document.body.offsetWidth <= 700) {
        this.isCollapse = true;
      } else {
        this.isCollapse = false;
      }
    }
  },
  created() {
    this.handleResize;
    window.addEventListener("resize", this.handleResize);
  }
};
</script>

<style lang="scss" scoped>
.asders {
  height: 100%;
  background: url("../../assets/OIP-C.jpg") center, center/cover;
}
.el-menu {
  height: 100%;
  transition: all linear 0.3s;
}
.boxbody {
  height: 50px;
  display: flex;
  padding: 30px;
  align-items: center;

  background: url("../../assets/OIP-C.jpg") center center/cover;
  div {
    text-align: center;
    color: rgb(83, 50, 50);
    font-size: 18px;
    font-weight: bold;
  }
}
.el-aside {
  color: #333;
  text-align: center;
  line-height: 200px;
  height: 100%;
}
</style>
相关推荐
四喜花露水20 分钟前
Vue 自定义icon组件封装SVG图标
前端·javascript·vue.js
前端Hardy29 分钟前
HTML&CSS: 实现可爱的冰墩墩
前端·javascript·css·html·css3
web Rookie1 小时前
JS类型检测大全:从零基础到高级应用
开发语言·前端·javascript
工业甲酰苯胺1 小时前
C# 单例模式的多种实现
javascript·单例模式·c#
程序员爱技术5 小时前
Vue 2 + JavaScript + vue-count-to 集成案例
前端·javascript·vue.js
悦涵仙子6 小时前
CSS中的变量应用——:root,Sass变量,JavaScript中使用Sass变量
javascript·css·sass
兔老大的胡萝卜6 小时前
ppk谈JavaScript,悟透JavaScript,精通CSS高级Web,JavaScript DOM编程艺术,高性能JavaScript pdf
前端·javascript
cs_dn_Jie9 小时前
钉钉 H5 微应用 手机端调试
前端·javascript·vue.js·vue·钉钉
开心工作室_kaic10 小时前
ssm068海鲜自助餐厅系统+vue(论文+源码)_kaic
前端·javascript·vue.js
有梦想的刺儿10 小时前
webWorker基本用法
前端·javascript·vue.js