index.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <template>
  2. <div class="first-menu">
  3. <a-menu
  4. class="a-menu_container"
  5. theme="dark"
  6. v-model:selectedKeys="current"
  7. @click="menuClick"
  8. mode="horizontal"
  9. >
  10. <a-menu-item :key="String(index)" v-for="(item, index) in list">{{ item[value] }}</a-menu-item>
  11. </a-menu>
  12. <div class="menu_right">
  13. <slot></slot>
  14. </div>
  15. </div>
  16. </template>
  17. <script lang="ts">
  18. import { defineComponent, PropType, ref, watchEffect } from 'vue';
  19. interface Key {
  20. [propName: string]: string;
  21. }
  22. export default defineComponent({
  23. name: 'first-menu',
  24. emits: ['selectMenu'],
  25. props: {
  26. list: {
  27. default: [],
  28. type: Object as PropType<Key[]>,
  29. },
  30. value: {
  31. // 需要绑定的值得 key
  32. default: '',
  33. type: String,
  34. },
  35. selectedKey: {
  36. default: ['0'],
  37. type: Array as PropType<string[]>,
  38. },
  39. },
  40. components: {},
  41. setup(props, context) {
  42. const current = ref<string[]>(['0']);
  43. watchEffect(() => {
  44. current.value = props.selectedKey;
  45. });
  46. function menuClick(value: any) {
  47. const index = +value.key;
  48. context.emit('selectMenu', props.list[index]);
  49. }
  50. return {
  51. current,
  52. menuClick,
  53. };
  54. },
  55. });
  56. </script>
  57. <style lang="less">
  58. .noBorderBottom {
  59. border-bottom: none;
  60. }
  61. </style>;