2021-09-29 01:42:11 +00:00
|
|
|
<template>
|
|
|
|
<div class="layui-collapse">
|
2021-10-12 03:30:07 +00:00
|
|
|
<slot />
|
2021-09-29 01:42:11 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2021-10-12 04:58:17 +00:00
|
|
|
<script setup name="LayCollapse"></script>
|
|
|
|
<script setup lang="ts">
|
2021-12-08 15:46:42 +00:00
|
|
|
import { withDefaults, defineProps, provide, ref, defineEmits, watch } from 'vue'
|
2021-10-12 04:58:17 +00:00
|
|
|
|
|
|
|
const props = withDefaults(
|
|
|
|
defineProps<{
|
2021-12-08 15:46:42 +00:00
|
|
|
modelValue?: number | string | [];
|
|
|
|
accordion?: boolean;
|
2021-10-12 04:58:17 +00:00
|
|
|
}>(),
|
|
|
|
{
|
2021-12-08 15:46:42 +00:00
|
|
|
modelValue: () => [],
|
|
|
|
accordion: false
|
2021-10-12 04:58:17 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2021-12-08 15:46:42 +00:00
|
|
|
// 监听传入的值
|
|
|
|
watch(
|
|
|
|
() => props.modelValue,
|
|
|
|
(val, oldVal)=>{
|
|
|
|
activeValues.value = ([] as any[]).concat(val)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
const emit = defineEmits(["update:modelValue", "change"])
|
|
|
|
|
|
|
|
const activeValues = ref<Array<any>>(([] as any[]).concat(props.modelValue));
|
|
|
|
|
|
|
|
provide("layCollapse", {
|
|
|
|
accordion : props.accordion,
|
|
|
|
activeValues,
|
|
|
|
emit
|
|
|
|
})
|
2021-10-12 04:58:17 +00:00
|
|
|
|
|
|
|
</script>
|