vue treeselect 禁止选择某些节点

vue treeselect 实现了下拉选择树,但现在有一个需求是,下拉节点有三种类型(代号为1,2,3),如果类型是1或者2的话,禁止该节点被选中。其实这些在文档中有了挺详细的描述了:https://www.vue-treeselect.cn/#disable-item-selection

自己再记一下

<treeselect
:options="options"
:value="value"
:flat="true"
:normalizer="my_normalizer"
/>

注意一点就是,默认是flat属性为false,这时如果禁止父节点选中的话,该父节点下的所有节点都会被禁止选中,因此要设置一下flat

 自定义的 normalizer

 my_normalizer(node) {
      return {
        id: node.xxxid,
        label: node.xxxlabel,
        children: node.children,
        isDisabled: node.type==1 || node.type==2 ? true : false
      };
    },

这样就大概可以了。

原文地址:https://www.cnblogs.com/Guhongying/p/14514577.html