layui/src/module/menu/index.vue

51 lines
910 B
Vue
Raw Normal View History

2021-09-29 15:42:53 +00:00
<template>
<ul class="layui-nav" :class="[tree ? 'layui-nav-tree' : '']">
<slot />
</ul>
2021-09-29 15:42:53 +00:00
</template>
<script setup name="LayMenu" lang="ts">
import { computed, defineProps, provide, ref, watch } from 'vue'
const emit = defineEmits(['update:selectedKey', 'update:openKeys'])
2021-09-29 15:42:53 +00:00
2021-10-08 03:09:44 +00:00
const props = withDefaults(
2021-10-01 10:20:41 +00:00
defineProps<{
2021-10-08 03:09:44 +00:00
selectedKey?: string
openKeys?: string[]
2021-10-03 14:47:49 +00:00
tree?: boolean
2021-10-08 03:09:44 +00:00
}>(),
{
selectedKey: '',
openKeys: function () {
return []
},
2021-10-08 03:09:44 +00:00
tree: false,
}
)
2021-10-06 11:09:03 +00:00
const isTree = computed(() => props.tree)
2021-10-06 11:09:03 +00:00
const openKeys = computed({
get() {
return props.openKeys
},
set(val) {
emit('update:selectedKey', val)
},
})
const selectedKey = computed({
get() {
return props.selectedKey
},
set(val) {
emit('update:selectedKey', val)
},
})
provide('isTree', isTree)
provide('selectedKey', selectedKey)
provide('openKeys', openKeys)
2021-09-29 15:42:53 +00:00
</script>