解决ant design vue使用tree select树选择器时父节点需要不可选中的问题

在使用antv的tree select树选择器时,发现默认它的父节点是可以选中的。在用户使用的时候,很多时候是不需要选中的。

查看了他的api发现一个属性selectable,默认为true

 所以我们只需要在给这个tree数组赋值的时候,给父节点赋selectable为false就可以了。

// 获取项目对应的政府性技能科目下拉框
      getMajorProject() {
        const url = `/specialbond/zwMhkZxzq/queryFundSubjectsTree`
        this.axios.get(url).then(res => {
          if (res.result) {
            let _menu = res.result
            _menu.forEach(item => {
              let children = []
              if(item.children) {
                item.children.forEach(itemC => {
                children.push({value: itemC.key, title: itemC.title})
              })
              this.fundSubjectsList.push({title: item.title, value: item.key, selectable:false, children: children})
              } else {
                this.fundSubjectsList.push({title: item.title, value: item.key, children: []})
              }
            })
          } else {
            this.$message.error('获取数据失败')
          }
        })
      },

同理,如果需要禁用的话,直接disabled为true就可以。 

猜你喜欢

转载自blog.csdn.net/weixin_44320032/article/details/126852645
今日推荐