layui/src/module/collapse/index.vue

40 lines
765 B
Vue
Raw Normal View History

<template>
<div class="layui-collapse">
<slot />
</div>
</template>
<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'
const props = withDefaults(
defineProps<{
2021-12-08 15:46:42 +00:00
modelValue?: number | string | [];
accordion?: boolean;
}>(),
{
2021-12-08 15:46:42 +00:00
modelValue: () => [],
accordion: false
}
)
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
})
</script>