perf: 修改 use 为 hooks

This commit is contained in:
就眠仪式
2021-10-24 23:41:19 +08:00
parent 2145e0d2c5
commit dd8f37181a
12 changed files with 28 additions and 15 deletions

View File

@@ -40,6 +40,7 @@ import {
ref,
onUpdated,
onMounted,
watch,
} from 'vue'
const slot = useSlots()
@@ -57,16 +58,6 @@ const setItemInstanceBySlot = function (nodeList: VNode[]) {
})
}
onUpdated(() => {
childrens.value = []
setItemInstanceBySlot((slot.default && slot.default()) as VNode[])
})
onMounted(() => {
childrens.value = []
setItemInstanceBySlot((slot.default && slot.default()) as VNode[])
})
const props = defineProps<{
type?: string
modelValue: string
@@ -83,6 +74,7 @@ const active = computed({
emit('update:modelValue', val)
},
})
const slotsChange = ref(true)
const change = function (id: any) {
emit('update:modelValue', id)
@@ -93,5 +85,11 @@ const close = function (id: any) {
emit('close', id)
}
watch(slotsChange, function () {
childrens.value = []
setItemInstanceBySlot((slot.default && slot.default()) as VNode[])
})
provide('active', active)
provide('slotsChange', slotsChange)
</script>