[Vue-Treeselect Warning] Unloaded branch node detected. “loadOptions“ prop i

问题:使用Vue treeselect时出现了[Vue-Treeselect Warning] Unloaded branch node detected. “loadOptions” prop is required to load its children.的错误提示。

原因:treeselect需要的数组children如果为空,应该直接把这个children属性去掉,否则就会报上述错误。而后端传递过来的数据中,当children为空时,赋值为null,所以导致了报上述的错误。

解决方案:normalizer 属性,代码如下:

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

你可能感兴趣的:(vue.js,前端,javascript)