引入子组件
<CheckTreee @nodeClicked="nodeClicked"></CheckTreee>
子组件中获取选中的id
<el-tree
ref="treesRef"
style="max-width: 600px"
:data="dataTree"
node-key="id"
:props="defaultProps"
show-checkbox
:expand-on-click-node="false"
@check-change="handleClick"
/>
let checkID = ref<any[]>([]);
const handleClick = async (node: any, isCheck: any) => {
if (isCheck) {
checkID.value.push(node.id);
} else {
checkID.value.forEach((item, i) => {
if (item === node.id) {
checkID.value.splice(i, 1);
}
});
}
emit("nodeClicked", checkID);
};
///根据id取调用接口查数据
const nodeClicked = (val: any) => {
selectData.type = val.value.join(",");
getData(selectData);
};
方法一:
方法二: