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-24 05:42:56 +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: () => [],
|
2021-12-24 05:42:56 +00:00
|
|
|
accordion: false,
|
2021-10-12 04:58:17 +00:00
|
|
|
}
|
2021-12-24 05:42:56 +00:00
|
|
|
);
|
2021-10-12 04:58:17 +00:00
|
|
|
|
2021-12-08 15:46:42 +00:00
|
|
|
// 监听传入的值
|
|
|
|
watch(
|
2021-12-24 05:42:56 +00:00
|
|
|
() => props.modelValue,
|
|
|
|
(val, oldVal) => {
|
|
|
|
activeValues.value = ([] as any[]).concat(val);
|
2021-12-08 15:46:42 +00:00
|
|
|
}
|
2021-12-24 05:42:56 +00:00
|
|
|
);
|
|
|
|
const emit = defineEmits(["update:modelValue", "change"]);
|
2021-12-08 15:46:42 +00:00
|
|
|
|
|
|
|
const activeValues = ref<Array<any>>(([] as any[]).concat(props.modelValue));
|
|
|
|
|
|
|
|
provide("layCollapse", {
|
2021-12-24 05:42:56 +00:00
|
|
|
accordion: props.accordion,
|
2021-12-08 15:46:42 +00:00
|
|
|
activeValues,
|
2021-12-24 05:42:56 +00:00
|
|
|
emit,
|
|
|
|
});
|
2021-10-12 04:58:17 +00:00
|
|
|
</script>
|