From 98dbbf2e88dbfe8ab3023a1eb4e8827f1eb2e5c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=9D=E5=85=88=E7=91=9E?= <1490493387@qq.com> Date: Sat, 5 Mar 2022 16:28:24 +0800 Subject: [PATCH] =?UTF-8?q?refactor(TreeSelect.vue):=20=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/TreeSelect/index.vue | 30 +++++++++++++---------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/components/TreeSelect/index.vue b/src/components/TreeSelect/index.vue index a4837f7e..db3dd43a 100644 --- a/src/components/TreeSelect/index.vue +++ b/src/components/TreeSelect/index.vue @@ -82,22 +82,6 @@ const modelValue = computed({ const valueTitle = ref(''); const defaultExpandedKey = ref([]); -function initHandle() { - nextTick(() => { - const selectedValue = modelValue.value; - if (selectedValue !== null && typeof (selectedValue) !== "undefined") { - const node = proxy.$refs.selectTree.getNode(selectedValue) - if (node) { - valueTitle.value = node.data[state.props.label] - proxy.$refs.selectTree.setCurrentKey(selectedValue) // 设置默认选中 - defaultExpandedKey.value = [selectedValue] // 设置默认展开 - } else { - clearHandle() - } - } - }) -} - function handleNodeClick(node) { valueTitle.value = node[state.props.label] modelValue.value = node[state.props.value]; @@ -128,7 +112,19 @@ function clearSelected() { } onMounted(() => { - initHandle() + nextTick(() => { + const selectedValue = modelValue.value; + if (selectedValue !== null && typeof (selectedValue) !== "undefined") { + const node = proxy.$refs.selectTree.getNode(selectedValue) + if (node) { + valueTitle.value = node.data[state.props.label] + proxy.$refs.selectTree.setCurrentKey(selectedValue) // 设置默认选中 + defaultExpandedKey.value = [selectedValue] // 设置默认展开 + } else { + clearHandle() + } + } + }) }) watch(modelValue, () => {