• Vue3 组件递归


    父组件调用 sub-menu 子组件

    1. 引入子组件模板 import SingleFileRecursiveSubMenu from "@/components/menus/SingleFileRecursiveSubMenu"; 

    2. 注册子组件 'sub-menu': SingleFileRecursiveSubMenu

    3. 使用子组件 <sub-menu :menu-info="item" :key="item.cddm" />

    <template>
      <div>
        <a-menu
          mode="inline"
          class="h-100 w-100"
          theme="dark"
          :subMenuOpenDelay="1"
          @click="handleClick"
        >
          <template v-for="item in menuItems" :key="item.cddm">
            <template v-if="!item.children">
              <a-menu-item :key="item.cddm">{{ item.cdmc }}</a-menu-item>
            </template>
            <template v-else>
              <sub-menu :menu-info="item" :key="item.cddm" />
            </template>
          </template>
        </a-menu>
      </div>
    </template>
    
    <script>
    
    import { ref, reactive } from "vue";
    import SingleFileRecursiveSubMenu from "@/components/menus/SingleFileRecursiveSubMenu";
    
    const componentsMixin = {
      components: {
        'sub-menu': SingleFileRecursiveSubMenu,
      },
    };

    子组件递归调用自身

    使用组件中的 name 属性

    <template>
      <div>
        <a-sub-menu :key="menuInfo.cddm">
          <template #title>{{ menuInfo.cdmc }}</template>
          <template v-for="item in menuInfo.children" :key="item.cddm">
            <template v-if="!item.children">
              <a-menu-item :key="item.cddm">{{ item.cdmc }}</a-menu-item>
            </template>
            <template v-else>
              <sub-menu :menu-info="item" :key="item.cddm" />
            </template>
          </template>
        </a-sub-menu>
      </div>
    </template>
    <script>
    import { toRefs } from "vue";
    
    export default {
      name: "sub-menu",
      props: ['menuInfo'],
      setup(props) {
        const {menuInfo} = toRefs(props)
        return {
          menuInfo
        };
      },
    };
    </script>
  • 相关阅读:
    2019.7.28刷题统计
    2019.7.27刷题统计
    2019.7.26刷题统计
    2019.7.22刷题统计
    qdoj.xyz 6.18
    qdoj.xyz 6.17
    qdoj.xyz 6.16
    qdoj.xyz 6.15
    qdoj.xyz 6.14
    qdoj.xyz 6.13
  • 原文地址:https://www.cnblogs.com/ghostnet/p/15152627.html
Copyright © 2020-2023  润新知