layui/src/component/menu/index.vue

60 lines
1.2 KiB
Vue
Raw Normal View History

2022-01-31 23:23:20 +00:00
<script lang="ts">
export default {
name: "LayMenu"
}
</script>
2021-09-29 15:42:53 +00:00
2022-01-31 23:23:20 +00:00
<script setup lang="ts">
import { computed, provide } from "vue";
2022-01-28 03:43:48 +00:00
import "./index.less";
export interface LayMenuProps {
selectedKey?: string;
openKeys?: string[];
tree?: boolean;
theme?: string;
2022-01-30 12:29:16 +00:00
inverted?: boolean;
2022-01-30 13:50:38 +00:00
level?: boolean;
}
const emit = defineEmits(["update:selectedKey", "update:openKeys"]);
const props = withDefaults(defineProps<LayMenuProps>(), {
selectedKey: "",
openKeys: () => [],
tree: false,
2022-01-30 12:29:16 +00:00
theme: 'dark',
2022-01-30 13:50:38 +00:00
inverted: false,
level: false
});
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>
2022-01-31 23:23:20 +00:00
<template>
<ul class="layui-nav" :class="[level? 'level':'',inverted ? 'inverted':'',tree ? 'layui-nav-tree' : '', theme === 'dark' ? 'layui-nav-dark':'layui-nav-light' ]">
<slot></slot>
</ul>
</template>