国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

vue3 element-plus動(dòng)態(tài)菜單及動(dòng)態(tài)圖標(biāo)

這篇具有很好參考價(jià)值的文章主要介紹了vue3 element-plus動(dòng)態(tài)菜單及動(dòng)態(tài)圖標(biāo)。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

1. 安裝element-plus及圖標(biāo)庫

# NPM
$ npm install @element-plus/icons-vue
# Yarn
$ yarn add @element-plus/icons-vue
# pnpm
$ pnpm install @element-plus/icons-vue


# NPM
$ npm install element-plus --save

# Yarn
$ yarn add element-plus

# pnpm
$ pnpm install element-plus

2.全局引入

引入element-plus

//引入element-plus
import ElementPlus from 'element-plus'
const app = createApp(App)
app.use(ElementPlus)

注冊(cè)圖標(biāo)組件

// main.ts

// 如果您正在使用CDN引入,請(qǐng)刪除下面一行。
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

3. 動(dòng)態(tài)菜單代碼

動(dòng)態(tài)引入圖標(biāo)代碼

<el-icon>
   <component  v-if="item.meta" :is="item.meta.icon"></component>
</el-icon>

完整代碼

<template>
  <el-menu
    active-text-color="#ffd04b"
    background-color="#545c64"
    text-color="#fff"
    default-active="2"
    router
    class="el-menu-vertical-demo"
    :collapse="props.isCollapse"
    :ellipsis="false"
    @open="handleOpen"
    @close="handleClose"
  >
    <!-- <el-sub-menu index="/home">
      <template #title>
        <el-icon><location /></el-icon>
        <span>常用功能</span>
      </template>
        <el-menu-item index="/throttle">節(jié)流</el-menu-item>
        <el-menu-item index="/debounce">防抖</el-menu-item>
    </el-sub-menu>
    <el-menu-item index="2">
      <el-icon><icon-menu /></el-icon>
      <template #title>Navigator Two</template>
    </el-menu-item>
    <el-menu-item index="3" disabled>
      <el-icon><document /></el-icon>
      <template #title>Navigator Three</template>
    </el-menu-item>
    <el-menu-item index="4">
      <el-icon><setting /></el-icon>
      <template #title>Navigator Four</template>
    </el-menu-item> -->
    <template v-for="item in menuRoutes" :key="item.id">
        <el-sub-menu  v-if="item.children && item.children.length > 0" :index="item.path">
          <template #title>
            <el-icon>
              <component  v-if="item.meta" :is="item.meta.icon"></component>
            </el-icon>
              <!-- <el-icon><location /></el-icon> -->
              <span v-if="item.meta">{{item.meta.title}}</span>
          </template>
          <!-- 二級(jí)菜單 -->
            <el-menu-item v-for="item2 in item.children" :key="item2.id" :index="item2.path" :style="item2.children?'display: none': null">
              {{item2.children? null : item2.meta.title}}
            </el-menu-item>
          <!-- 三級(jí)菜單 -->
            <el-sub-menu v-for="item2 in item.children.filter(x => x.children && x.children.length > 0)" :key="item2.id" class="child-sub-menu" :index="item2.path">
              <template #title>
                <!-- <component  v-if="item.meta" :is="item.meta.icon" style="width: 20px; height: 20px"></component> -->
                <!-- <el-icon><location /></el-icon> -->
                  <span v-if="item2.meta">{{item2.meta.title}}</span>
              </template>
              <el-menu-item v-for="item3 in item2.children" :key="item3.id" :index="item3.path">{{item3.meta.title}}</el-menu-item>
            </el-sub-menu>
          <!-- </template> -->
        </el-sub-menu>
        <el-menu-item v-else :index="item.path">{{item.meta.title}}</el-menu-item>
    </template>
  </el-menu>
</template>

<script lang="ts" setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { menuRoutes } from '@/router/index'
const router = useRouter()
const props = defineProps({
  isCollapse: {
		type: Boolean,
		default: false,
  }
})
const emits = defineEmits(['menuChange'])
const handleOpen = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}
const handleClose = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}
onMounted(() => {
    console.log(router.options.routes)
})
</script>

<style>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
</style>
<style lang="stylus" scoped>
.el-menu
  height: 100vh
  border-right: none
:deep(.el-sub-menu__title)
  height: 50px !important
</style>

路由如下文章來源地址http://www.zghlxwxcb.cn/news/detail-802734.html

export const menuRoutes: Array<RouteRecordRaw> = [
    {
        path: '/adminHome',
        name: 'adminHome',
        meta: {
            title: '常用功能',
            icon: 'location'
        },
        component: () => import('@/views/adminHome.vue'),
        children: [
            {
                path: '/debounce',
                name: 'debounce',
                meta: {
                    title: '防抖',
                    icon: 'location'
                },
                component: () => import('@/views/adminsystem/debounce/index.vue')
            },
            {
                path: '/throttle',
                name: 'throttle',
                meta: {
                    title: '節(jié)流',
                    icon: 'location'
                },
                component: () => import('@/views/adminsystem/throttle/index.vue')
            }
        ]
    }
]

到了這里,關(guān)于vue3 element-plus動(dòng)態(tài)菜單及動(dòng)態(tài)圖標(biāo)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • vue3.x結(jié)合element-plus如何使用icon圖標(biāo)

    vue3.x結(jié)合element-plus如何使用icon圖標(biāo)

    ?基于 Vue 3的Element Plus如何使用icon圖標(biāo) 首先注意Element Plus版本:官網(wǎng)如圖所示, ?基于vue3的具體如何使用: 參考官網(wǎng)文檔: 1.首先選擇一種方式安裝 ?2.然后全局注冊(cè)圖標(biāo) 在main.js或main.ts文件中引入: ?3.然后就可以使用了,具體實(shí)例如下: 使用方式1:輸入框中使用 輸入框

    2023年04月08日
    瀏覽(22)
  • Vue3 element-plus表單嵌套表格實(shí)現(xiàn)動(dòng)態(tài)表單驗(yàn)證

    Vue3 element-plus表單嵌套表格實(shí)現(xiàn)動(dòng)態(tài)表單驗(yàn)證

    部分效果圖如下: 另表格有添加和刪除按鈕,點(diǎn)擊提交進(jìn)行表單驗(yàn)證。 首先data格式必須是對(duì)象包裹數(shù)組 給表單綁定form數(shù)據(jù) 表格綁定tableData數(shù)據(jù) 給表單項(xiàng)增加驗(yàn)證規(guī)則 rules對(duì)應(yīng)data rules對(duì)象,prop對(duì)應(yīng)表單字段(注意是表格里每一行對(duì)應(yīng)的字段 forms.tableData[下標(biāo)].key) prop的關(guān)

    2024年02月14日
    瀏覽(25)
  • Vue3中動(dòng)態(tài)綁定:disabled element-plus使用方法

    @change=\\\"whetherFlag($event)\\\"? 根據(jù)value值判斷是否禁用?:disabled=\\\"isShow\\\" 初始值為禁用狀態(tài) const isShow = refboolean(true); ?根據(jù)value的值判斷是否禁用 ?

    2024年01月25日
    瀏覽(30)
  • element-plus 動(dòng)態(tài)Icon圖標(biāo)

    目錄 1,前言 2,使用 2.1,方式一 2.2,方式二 源自 Element Plus 團(tuán)隊(duì)正在將原有組件內(nèi)的 Font Icon 向 SVG Icon 遷移,請(qǐng)多多留意更新日志, 及時(shí)獲取到更新信息,F(xiàn)ont Icon 將會(huì)在第一個(gè)正式發(fā)布被廢棄,請(qǐng)盡快遷移 在此記錄一下如何使用element-plus中的icon組件 環(huán)境: Vue:3.2.16 Elem

    2024年02月16日
    瀏覽(23)
  • Vue3 + Element Plus 實(shí)現(xiàn)動(dòng)態(tài)標(biāo)簽頁及右鍵菜單

    Vue3 + Element Plus 實(shí)現(xiàn)動(dòng)態(tài)標(biāo)簽頁及右鍵菜單

    目錄 先上圖 ?使用el-dropdown綁定右鍵菜單,為每個(gè)tab頁綁定一個(gè)右鍵 右鍵菜單生效后控制每個(gè)下拉項(xiàng)的禁用與顯示(每一項(xiàng)代表一個(gè)功能) 每個(gè)右鍵項(xiàng)對(duì)應(yīng)的功能? 控制每次只顯示一個(gè)右鍵 完整代碼 ????????只有首頁的情況 ????????多個(gè)tab頁的情況 ?

    2024年02月07日
    瀏覽(23)
  • Vue3+Element-Plus 實(shí)現(xiàn)用戶列表頁面的UI結(jié)構(gòu)及動(dòng)態(tài)加載表單功能 三一

    Vue3+Element-Plus 實(shí)現(xiàn)用戶列表頁面的UI結(jié)構(gòu)及動(dòng)態(tài)加載表單功能 三一

    1.1 頭部是一個(gè)面包屑?(Breadcrumb)導(dǎo)航區(qū)域 1.2 白色區(qū)域是一個(gè)卡片(Card)視圖 1.3 卡片 (Card)視圖中嵌套了 ? 輸入框(Input )、 按鈕(Button)、 表單(Form)、分頁(Pagination ) Breadcrumb 面包屑 | Element Plus (gitee.io) https://element-plus.gitee.io/zh-CN/component/breadcrumb.html ?2.1.1 復(fù)制

    2023年04月09日
    瀏覽(32)
  • vue3+ts+element-plus 之使用node.js對(duì)接mysql進(jìn)行表格數(shù)據(jù)展示

    vue3+ts+element-plus 之使用node.js對(duì)接mysql進(jìn)行表格數(shù)據(jù)展示

    * 初始化node 查看node是否安裝 node -v 初始化命令 npm init 初始化配置解釋如下: 完成后會(huì)有一個(gè)package.json文件 * 安裝可能用到的依賴 根據(jù)需求安裝,我這里需要對(duì)接mysql,安裝依賴 ,我是一次性安裝完,后邊會(huì)直接使用,也可以邊安裝邊使用。如下 安裝成功如下: * 配置文件

    2024年02月15日
    瀏覽(54)
  • Vue3+Vue-Router+Element-Plus根據(jù)后端數(shù)據(jù)實(shí)現(xiàn)前端動(dòng)態(tài)路由——權(quán)限管理模塊

    Vue3+Vue-Router+Element-Plus根據(jù)后端數(shù)據(jù)實(shí)現(xiàn)前端動(dòng)態(tài)路由——權(quán)限管理模塊

    提示:文章內(nèi)容仔細(xì)看一些,或者直接粘貼復(fù)制,效果滿滿 提示:文章大概 1、項(xiàng)目:前后端分離 2、前端:基于Vite創(chuàng)建的Vue3項(xiàng)目 3、后端:沒有,模擬的后端數(shù)據(jù) 4、關(guān)于路徑“@”符號(hào)——vite.config.js 文件里修改 提示:以下是本篇文章正文內(nèi)容,下面案例可供復(fù)制粘貼使用

    2024年02月02日
    瀏覽(123)
  • vue3使用element-plus

    vue3使用element-plus

    element-ui 是配合 vue2 使用,element-plus 是配置 vue3 使用的 1. 包管理器的方式 如果是使用?webpack 或者 vite 打包工具新建的項(xiàng)目 2. 瀏覽器直接導(dǎo)入 直接通過瀏覽器的 HTML 標(biāo)簽導(dǎo)入 Element Plus,然后就可以使用全局變量 ElementPlus 1. 導(dǎo)入全部組件且注冊(cè)所有的圖標(biāo) 聲明使用 ElementPl

    2024年02月08日
    瀏覽(35)
  • Vue3導(dǎo)入Element-plus方法

    Vue3導(dǎo)入Element-plus方法

    先引入依賴 main.js中要引入兩個(gè)依賴 然后 這個(gè)東西 我們最好還是掛載vue上 所以 還是 然后 我們可以在組件上試一下用一個(gè)ElementUi的表格組件 參考代碼如下 運(yùn)行結(jié)果如下 也是沒有任何問題

    2024年02月06日
    瀏覽(97)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包