当前位置: 代码迷 >> 综合 >> [Vue-Treeselect Warning] Unloaded branch node detected. “loadOptions“ prop is required to load its
  详细解决方案

[Vue-Treeselect Warning] Unloaded branch node detected. “loadOptions“ prop is required to load its

热度:8   发布时间:2023-12-14 04:51:10.0

使用Vue treeselect时出现了[Vue-Treeselect Warning] Unloaded branch node detected. “loadOptions” prop is required to load its children.错误。
原因是treeselect需要的数组children如果为空,应该直接把这个children属性去掉,否则就会报上述错误。
而后端传递过来的数据中,当children为空时,赋值为null,所以导致了报上述的错误。
解决方案:在treeselect标签中写入:normalizer=“normalizer” ,并在data()中创建一个normalizer方法,并在normalizer方法中写入下面的代码:

<treeselect v-model="deptId" :options="deptOptions" :disable-branch-nodes="true" :normalizer="normalizer" :show-count="true" placeholder="请选择归属部门" />
normalizer(node){//去掉children=null的属性if(node.children==null||node.children=='null'){delete node.children;}},

 

  相关解决方案