perf(collapse): 删除 collapseItem 的 show 配置, 使用 collapse openKeys 替换

This commit is contained in:
就眠仪式
2021-10-12 12:58:17 +08:00
parent 55da634f7c
commit 16934254ab
3 changed files with 37 additions and 9 deletions

View File

@@ -4,4 +4,21 @@
</div>
</template>
<script setup name="LayCollapse" lang="ts"></script>
<script setup name="LayCollapse"></script>
<script setup lang="ts">
import { withDefaults, defineProps, provide } from 'vue'
const props = withDefaults(
defineProps<{
openKeys: string[]
}>(),
{
openKeys: function () {
return []
},
}
)
provide("openKeys",props.openKeys)
</script>

View File

@@ -13,16 +13,23 @@
</template>
<script setup name="LayCollapseItem" lang="ts">
import { defineProps, Ref, ref } from 'vue'
import { defineProps, inject, Ref, ref } from 'vue'
const props = defineProps<{
show?: boolean
title?: string
id: string
title: string
}>()
const isShow = ref(props.show) as Ref
const openKeys = inject("openKeys") as String[]
const isShow = ref(openKeys.includes(props.id))
const showHandle = function () {
isShow.value = !isShow.value
if(openKeys.indexOf(props.id) != -1) {
openKeys.splice(openKeys.indexOf(props.id),1)
} else {
openKeys.push(props.id)
}
}
</script>