antd动态导航

<script setup lang="ts">
import {useCounterStore} from "@/stores/counter";
import {useRouter} from "vue-router";
import { h, ref, onMounted } from 'vue';
import type { MenuProps } from 'ant-design-vue';
import { ItemType } from 'ant-design-vue';
const router=useRouter()
const store = useCounterStore()

const imgs='https://ts1.cn.mm.bing.net/th/id/R-C.9e45a633e95179a37c907fa2797999ad?rik=aMuPS4TunAh5ZA&riu=http%3a%2f%2fwww.quazero.com%2fuploads%2fallimg%2f140303%2f1-140303214Q2.jpg&ehk=P%2firfYpARc1fHht%2bWpapYR4W15p6SLABE8CBexoeon4%3d&risl=&pid=ImgRaw&r=0'

function getItem(
    label: string,
    key: string,
    icon?: any,
    children?: ItemType[],
    type?: 'group',
): ItemType {
  return {
    key,
    icon,
    children,
    label,
    type,
  } as ItemType;
}
const current = ref<string[]>(['/class']);
const items = ref<MenuProps['items']>([]);
let list=[
  {label:'首页',key:'/'},
  {label:'类',key:'/class'},
  {label:'表单',key:'/form',},
  {label:'二级',key:'/sub2',children:[
      {label:'关于',key:'/about'},
      {label:'我的',key:'/my'},
    ]},
]
let chilList=[]
const onclick=({ key })=>{
  router.push({path:key})
}
const forList=(list)=>{
  list.forEach(i=>{
    if(i.children){
      let chil=[]
      i.children.forEach(y=>{
        chil.push(getItem(y.label, y.key, h('img',{
          style: {
            width: '16px',
            height: '16px',
          },
          src: imgs
        })))
      })
      chilList.push(getItem(i.label, i.key, h('img',{
        style: {
          width: '16px',
          height: '16px',
        },
        src: imgs
      }),[...chil]))
    }else{
      chilList.push(getItem(i.label, i.key, h('img',{
        style: {
          width: '16px',
          height: '16px',
        },
        src: imgs
      })))
    }
  })
}


onMounted(()=>{
  forList(list)
  items.value=chilList
})
</script>

<template>
  <a-menu
      v-model:selectedKeys="current"
      mode="inline"
      @click="onclick"
      :items="items"
  />
</template>

<style scoped>

</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值