关于el-tree横向折叠的实现

Element-UI官方文档Tree 树形控件只支持竖向折叠,不支持横向折叠,需要自己写事件,结合Vue v-if或v-show实现

1、el-col或者div设置v-show绑定显示标识

      <!--部门数据-->
      <el-col :span="4" :xs="24" v-show="showelcol">
        <div class="head-container">
          <el-input
            v-model="deptName"
            placeholder="请输入企业名称"
            clearable
            size="small"
            prefix-icon="el-icon-search"
            style="margin-bottom: 20px"/>
        </div>
        <div class="head-container">
          <el-tree
            :data="deptOptions"
            :props="defaultProps"
            :expand-on-click-node="false"
            :filter-node-method="filterNode"
            ref="tree"
            default-expand-all
            highlight-current
            @node-click="handleNodeClick"/>
        </div>
      </el-col>

2、数据设置showelcol: true,默认显示

data: function () {
  return {
   showelcol: true,
   iconData: 'el-icon-arrow-left',
     }
  }

3、添加按钮通过控制数据变化来控制el-col显示隐藏

  <el-button @click="changeShowelcol">显示/隐藏</el-button>
changeShowelcol(){
  this.showelcol=!this.showelcol;
},

   添加图标通过控制数据变化来控制el-col显示隐藏并动态切换图标

<el-button type="text" @click="changeShowelcol" class="icon-button" v-bind:icon="iconData"></el-button>
    changeShowelcol() {
      this.showelcol = !this.showelcol;
      if (!this.showelcol) {
        this.iconData = 'el-icon-arrow-right'
      } else {
        this.iconData = 'el-icon-arrow-left'
      }
    },

4、页面结构以及按钮位置

9643b9ad8d9a4ee0882125f927ca248e.png

 按钮位置只需要通过调节margin-top 使按钮调节到合适位置

<style scoped>
.icon-button {
  margin-top: 270px;
}
</style>

 也可以使用弹性布局使按钮在el-col中居中

<el-col :span="1" class="flex-center">
  <el-button type="text" @click="changeShowelcol" class="icon-button" v-bind:icon="iconData"></el-button>
</el-col>

.flex-center{
    height: 80vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

5、存在问题:隐藏el-col之后,页面会留一部分空白,非常不美观,

解决方法:对其他部分页面使用动态:span

<el-col :span="this.showelcol==true ? 20:24" :xs="24">

效果图:

5f0eb0715374427998e431f755bf5d46.png

 3371d50d66c54bd68e469a4a7709aee7.png

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

要成为大V的小v

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值