树形拖拽菜单刷新默认点击第一个、非默认选中。
ref="tree" node-key="id", setCurrentKey=>选中高亮
const treeRef = ref(null);
watch(
() => tree.data,
(nVal) => {
if (nVal) {
console.log(nVal[0].id);
$nextTick(() => {
if (diffType.value == 'add') {
treeRef.value.setCurrentKey(nVal[nVal.length - 1].id) ;
} else {
treeRef.value.setCurrentKey(nVal[0].id) ;
}
});
}
}
);
watch(
() => tree.data,
(nVal) => {
if (nVal) {
$nextTick(() => {
if (diffType.value == 'add') { //添加到最后一个 默认选中最后一个
let arr = document.querySelectorAll('.el-tree-node');
arr[arr.length - 1].click();
} else {
document.querySelector('.el-tree-node__content').click();//默认选中第一个
}
});
}
}
);