diff --git a/components/select-tree/selectTree.vue b/components/select-tree/selectTree.vue index 96f74bfb..94578177 100644 --- a/components/select-tree/selectTree.vue +++ b/components/select-tree/selectTree.vue @@ -124,7 +124,6 @@ import { unref, watch, computed, - onMounted, CSSProperties, PropType, } from 'vue'; @@ -206,6 +205,11 @@ export default defineComponent({ watch(isOpened, () => { emit('visibleChange', unref(isOpened)); + + // trigger 在mounted 之后可能会改变 + if (isOpened.value && triggerDomRef.value) { + triggerWidth.value = triggerDomRef.value.$el.offsetWidth; + } }); const handleChange = () => { @@ -341,12 +345,6 @@ export default defineComponent({ const triggerDomRef = ref(); const triggerWidth = ref(0); - onMounted(() => { - if (triggerDomRef.value) { - triggerWidth.value = triggerDomRef.value.$el.offsetWidth; - } - }); - const dropdownStyle = computed(() => { const style: CSSProperties = {}; if (triggerWidth.value) { diff --git a/components/select/select.vue b/components/select/select.vue index 399e142a..248a17fb 100644 --- a/components/select/select.vue +++ b/components/select/select.vue @@ -75,7 +75,6 @@ import { reactive, watch, computed, - onMounted, CSSProperties, defineComponent, } from 'vue'; @@ -137,6 +136,7 @@ export default defineComponent({ watch(isOpenedRef, () => { emit('visibleChange', unref(isOpenedRef)); + // trigger 在mounted 之后可能会改变 if (isOpenedRef.value && triggerRef.value) { triggerWidth.value = triggerRef.value.$el.offsetWidth; } @@ -373,12 +373,6 @@ export default defineComponent({ } }; - onMounted(() => { - if (triggerRef.value) { - triggerWidth.value = triggerRef.value.$el.offsetWidth; - } - }); - const dropdownStyle = computed(() => { const style: CSSProperties = {}; if (triggerWidth.value) { diff --git a/docs/.vitepress/components/selectTree/common.vue b/docs/.vitepress/components/selectTree/common.vue index 3e9dfe50..4011aa6c 100644 --- a/docs/.vitepress/components/selectTree/common.vue +++ b/docs/.vitepress/components/selectTree/common.vue @@ -28,9 +28,9 @@ function createLabel(level) { export default { setup() { const data = ref([]); - setTimeout(()=>{ - data.value = createData(4); - }) + setTimeout(() => { + data.value = createData(4); + }); return { data, };