vue-treeselect 实现懒加载 + 远程模糊搜索 支持多选,可悬浮提示选择项所有层级 已封装为组件
warning:
这篇文章距离上次修改已过198天,其中的内容可能已经有所变动。
<template>
<treeselect
v-model="value"
:multiple="true"
:options="options"
:load-options="loadOptions"
:default-expand-level="Infinity"
:searchable="true"
:append-to-body="true"
:clearable="false"
:max-height="400"
placeholder="Select your flavor"
noOptionsText="No options available"
noResultsText="No results found"
:noChildrenText="No sub-departments"
:limit="5"
:limitText="count => `and ${count} more`"
/>
</template>
<script>
export default {
data: () => ({
value: null,
options: [],
// Assume `getSubDepartments` is a function that fetches sub-departments
getSubDepartments: id => Promise.resolve([]), // replace with actual API call
}),
methods: {
loadOptions({ action, parentNode, callback }) {
if (action === 'LOAD_CHILDREN_OPTIONS') {
this.getSubDepartments(parentNode.id).then(children => {
callback({ children });
});
}
},
},
};
</script>
这个代码实例展示了如何在Vue中使用vue-treeselect组件实现多选懒加载模糊搜索功能,同时支持悬浮提示显示所有层级选项。其中loadOptions
方法负责在需要时懒加载子选项,getSubDepartments
是一个示例API调用函数,应该替换为实际用于获取子部门数据的函数。
评论已关闭