element tree异步树点击标题(label)加载

原创
2020/09/16 14:40
阅读数 177

最近使用element开发项目,在使用异步树时(即添加了lazy), 只有点击图标才会加载展开,操作体验不好,于是查询官方API尝试在节点单击时执行加载,发现没有相关接口。

经过分析源代码发现还是可以实现的。

      handleExpandIconClick() {
        if (this.node.isLeaf) return;
        if (this.expanded) {
          this.tree.$emit('node-collapse', this.node.data, this.node, this);
          this.node.collapse();
        } else {
          this.node.expand();
          this.$emit('node-expand', this.node.data, this.node, this);
        }
      },

从源码中可以看出在点击图标时判断节点是否已经展开,未展开就执行this.node.expand();执行数据加载并展开节点。

废话不多说,上我的代码:

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
0 评论
0 收藏
0
分享
返回顶部
顶部