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

vue3中使用ant-design-vue的layout組件實現(xiàn)動態(tài)導航欄功能(1~2級)

這篇具有很好參考價值的文章主要介紹了vue3中使用ant-design-vue的layout組件實現(xiàn)動態(tài)導航欄功能(1~2級)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

目錄

0 前言

1 準備工作

1.1 安裝ant-design-vue

1.2 安裝圖標組件包

2 選擇組件

3 路由文件

4 Vue導航頁面

5 最終效果


0 前言

????????最近在自己搞一個前后端小項目,前端想使用ant-design-vue的layout組件實現(xiàn)動態(tài)導航欄和面包屑,但是網(wǎng)上的資料較少,所以我就自己整合實現(xiàn)了一下,在此記錄分享。

1 準備工作

????????基于一個新建的Vue3項目上實現(xiàn)。

1.1 安裝ant-design-vue

? ? ? ? 官方文檔:Components Overview - Ant Design Vue (antdv.com)

????????安裝:

npm i --save ant-design-vue

????????全局注冊:

import { createApp } from 'vue';
import Antd from 'ant-design-vue';
import App from './App';
import 'ant-design-vue/dist/antd.css';

const app = createApp(App);

app.use(Antd).mount('#app');

1.2 安裝圖標組件包

npm install --save @ant-design/icons-vue

????????main.js中引用并全局注冊

import * as Icons from '@ant-design/icons-vue'
//全局注冊圖標
const icons = Icons
for (const i in icons) {
  app.component(i, icons[i])
}

2 選擇組件

????????如下圖所示,復制組件代碼:

antdesign 導航菜單動態(tài)顯示,vue.js,javascript,前端

3 路由文件

????????router/index.js文件

import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [
  {
    //導航頁
    path: '/layout',
    name: 'layout',
    meta: {
      title: '首頁',
      keepalive: true
    },
    component: () => import('@/views/layout/'),
    children: [
      {
        //歡迎頁
        path: '/layout',
        name: 'welcome',
        meta: {
          title: '首頁',
          keepalive: true
        },
        component: () => import('@/views/welcome/')
      },
      {
        //實時數(shù)據(jù)
        path: '/runtimeData',
        name: 'runtimeData',
        meta: {
          title: '實時數(shù)據(jù)',
          keepalive: true
        },
        component: () => import('@/views/runtimeData/')
      },
      {
        //數(shù)據(jù)分析
        path: '/dataAnalysis',
        name: 'dataAnalysis',
        meta: {
          title: '數(shù)據(jù)分析',
          keepalive: true
        },
        component: () => import('@/views/dataAnalysis/')
      },
      {
        //數(shù)據(jù)處理(增刪改查)
        path: '/dataManage',
        name: 'dataManage',
        meta: {
          title: '數(shù)據(jù)總覽',
          keepalive: true
        },
        component: () => import('@/views/dataManage/')
      },
      {
        //查看用戶信息
        path: '/showUserInfo',
        name: 'showUserInfo',
        meta: {
          title: '查看用戶信息',
          keepalive: true
        },
        component: () => import('@/views/my/showUserInfo.vue')
      },
      {
        //修改用戶信息
        path: '/editUserInfo',
        name: 'editUserInfo',
        meta: {
          title: '修改用戶信息',
          keepalive: true
        },
        component: () => import('@/views/my/editUserInfo.vue')
      },
    ]
  },
  {
    //登錄頁面
    path: '/login',
    name: 'login',
    meta: {
      title: '登錄',
      keepalive: true
    },
    component: () => import('@/views/login/index.vue')
  },

]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

export default router

4 Vue導航頁面

????????views/layout/index.vue,主要關注標簽a-layout中的內(nèi)容及相關變量

<template>
  <a-layout id="components-layout-demo-custom-trigger" style="min-height: 100vh">
    <a-layout-sider v-model:collapsed="collapsed" collapsible>

      <div class="logo">
        溫濕度數(shù)據(jù)顯示
      </div>


      <a-menu @click="navClick"
              v-model="currentSelectChild"
              @openChange="onOpenChange"
              :openKeys="currentParent"
              :inline-collapsed="collapsed"
              :selectedKeys="[route.path]"
              theme="dark"
              mode="inline"
      >

        <template v-for='(item,index) in NavDataInfo.NavData'>
          <a-sub-menu :key="item.Path" v-if='item.Child.length > 0'>
            <template #title>
              <a-icon>
                <meh-outlined/>
              </a-icon>
              <span>{{item.Title}}</span>
            </template>
            <a-menu-item v-for="(itChild,ind) in item.Child" :key="itChild.Path">
              <a-icon>
                <meh-outlined/>
              </a-icon>
              <router-link :to="itChild.Path">
                <!--根據(jù)路徑去跳轉(zhuǎn)頁面-->
                {{itChild.Title}}
              </router-link>
            </a-menu-item>
          </a-sub-menu>


          <a-menu-item :key="item.Path" v-else>
            <a-icon>
              <meh-outlined/>
            </a-icon>
            <router-link :to="item.Path">
              <a-icon :type="item.Icons"/>
              <span>{{item.Title}}</span>
            </router-link>
          </a-menu-item>

        </template>

      </a-menu>

    </a-layout-sider>
    <a-layout>
      <a-layout-header style="background: #fff; padding: 0">
        <div id="header">
          <div id="left">
            <span>作者:</span>
          </div>
          <div id="right">
            <a-avatar src="https://joeschmoe.io/api/v1/random"/>
            <el-dropdown>
              <span class="el-dropdown-link">
                User
                <el-icon class="el-icon--right">
                  <arrow-down />
                </el-icon>
              </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item><router-link to="/showUserInfo">我的信息</router-link></el-dropdown-item>
                  <el-dropdown-item><router-link to="/editUserInfo">修改信息</router-link></el-dropdown-item>
                  <el-dropdown-item><span @click="outLogin">退出登錄</span></el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </div>
        </div>
      </a-layout-header>
      <!--      <keep-alive>-->
      <a-layout-content style="margin: 0 16px">
        <!-- 面包屑 -->
        <a-breadcrumb style="margin: 16px 0" separator=">">
          <!-- 自定義返回函數(shù) ←-->
          <a-breadcrumb-item @click="goback">
            <a-icon>
              <import-outlined/>
            </a-icon>
            返回
          </a-breadcrumb-item>
          <a-breadcrumb-item v-for="(item, index) in breadList" :key="item.name">
            <router-link v-if="item.name !== name && index !== 1"
                         :to="{ path: item.path === '' ? '/' : item.path }">
              {{ item.meta.title }}
            </router-link>
            <span v-else>
              {{ item.meta.title }}
            </span>
          </a-breadcrumb-item>
        </a-breadcrumb>
        <!--          <transition>-->
        <div :style="{ padding: '24px', background: '#fff', minHeight: '100%' }">
          <router-view/>
        </div>
        <!--          </transition>-->
      </a-layout-content>
      <!--      </keep-alive>-->
      <a-layout-footer style="text-align: center">
        Great Project ?2022 Created by 
      </a-layout-footer>
    </a-layout>
  </a-layout>
</template>
<script setup>
  import { ref, reactive, onBeforeMount, watch, createVNode } from 'vue'
  import { useRouter, useRoute } from 'vue-router'
  import { Modal, message } from 'ant-design-vue'
  import { ExclamationCircleOutlined } from '@ant-design/icons-vue'
  import myRouter from '@/router'
  import { ArrowDown } from '@element-plus/icons-vue'
  //************************************************data部分
  const route = useRoute()
  const router = useRouter()
  const collapsed = ref(false)
  const selectedKeys = ref(['0'])
  const name = ref('')
  const breadList = ref([])
  const NavDataInfo = reactive({
    NavData: [
      {
        NavID: '0',
        Icons: 'home',
        Title: '首頁',
        Path: '/layout',
        Child: []
      },
      {
        NavID: '1',
        Icons: 'meh',
        Title: '實時數(shù)據(jù)',
        Path: '/runtimeData',
        Child: []
      },
      {
        NavID: '2',
        Icons: 'like',
        Title: '數(shù)據(jù)管理',
        Path: '/dataManage',
        Child: [
          {
            NavID: '2-1',
            Icons: 'man',
            Title: '數(shù)據(jù)總覽',
            Path: '/dataManage',
            Child: []
          },
        ]
      },
      {
        NavID: '3',
        Icons: 'key',
        Title: '數(shù)據(jù)分析',
        Path: '/dataAnalysis',
        Child: []
      },
    ],
  })
  //************************************************data部分

  //************************************************方法
  const getBreadcrumb = () => {
    breadList.value = []
    name.value = route.name
    route.matched.forEach(item => {
      breadList.value.push(item)
    })
    console.log(breadList.value)
    console.log(name.value)
    console.log(route)

  }
  // 返回上一頁,調(diào)用的組件 router.back();
  const goback = () => {
    //點擊了返回按鈕
    router.back()
  }

  //退出登錄
  const outLogin = () => {
    Modal.confirm({
      title: '您確定要退出登錄嗎?',
      icon: createVNode(ExclamationCircleOutlined),
      content: createVNode('div', {
        style: 'color:red;',
      }, '點擊OK則將退出!'),
      onOk () {
        // console.log('OK', key)
        message.success('退出登錄!')
        myRouter.push({ path: "/login" });
      },
      onCancel () {
        // console.log('Cancel')
        message.success('取消成功!')
      },
      class: 'test',
    })
  }

  //監(jiān)視路由
  watch(() => route.path, getBreadcrumb)

  //*************************************************方法

  //*************************************************生命周期
  onBeforeMount(() => {
    getBreadcrumb()
  })
  //*************************************************生命周期


</script>
<style scoped>
  #components-layout-demo-custom-trigger {
    height: 100%;
  }

  #components-layout-demo-custom-trigger .trigger {
    font-size: 18px;
    line-height: 64px;
    padding: 0 24px;
    cursor: pointer;
    transition: color 0.3s;
  }

  #components-layout-demo-custom-trigger .trigger:hover {
    color: #1890ff;
  }

  #components-layout-demo-custom-trigger .logo {
    height: 32px;
    background: rgb(127, 252, 255);
    margin: 16px;
    font-size: 20px;
    text-align: center;
    font-family: 宋體;
  }

  #header {
    display: flex;
    height: 70px;
    /*margin: 0;*/
    padding: 0;
  }

  #left {
    width: 80%;
    /*height: 25px;*/
    /*background-color: darksalmon;*/
    justify-content: flex-start;
    display: flex;
    align-items: center;
    margin-left: 16px;
  }

  #right {
    flex: 1;
    width: 20%;
    /*background-color: coral;*/
    /*height: 50px;*/
    justify-content: flex-end;
    display: flex;
    align-items: center;
    margin-right: 16px;
  }
  .example-showcase .el-dropdown-link {
    cursor: pointer;
    color: var(--el-color-primary);
    display: flex;
    align-items: center;
  }

</style>

????????上面的代碼中將路由文件中的路由表重新寫了一個變量,主要是為了方便,并不是所有頁面路由都要制作導航欄,這樣就不用在router/index.js中添加路由時考慮太多。

5 最終效果

antdesign 導航菜單動態(tài)顯示,vue.js,javascript,前端

?????????效果如上圖所示,我這里也寫了一個面包屑,不過還有些問題,就交給大伙兒實現(xiàn)吧!文章來源地址http://www.zghlxwxcb.cn/news/detail-618779.html

到了這里,關于vue3中使用ant-design-vue的layout組件實現(xiàn)動態(tài)導航欄功能(1~2級)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!

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

領支付寶紅包贊助服務器費用

相關文章

  • ant-design-vue在ios使用AUpload組件喚起了相機,HTML的 `capture` 屬性

    ant-design-vue在ios使用AUpload組件喚起了相機,HTML的 `capture` 屬性

    在使用ant design vue組件的上傳組件AUpload的時候有一個問題,直接按照demo寫,在ios上會喚起相機,但是實際上我們的需求是彈出選擇相冊/相機這個彈框。 解決辦法是加一個?cupture=\\\"null\\\"這個屬性即可 HTML attribute: capture - HTML: HyperText Markup Language | MDN The capture attribute specifies that

    2024年02月12日
    瀏覽(18)
  • [ant-design-vue] table組件列寬拖拽功能

    原有的樣式文件沒有使用的必要,個人添加的部分樣式內(nèi)容就符合需求了 vue3.x對應的ant-design-vue中的table組件本身支持列寬的拖動了,不需求額外的包的支持,根據(jù)Api說明設置resizeColumn即可

    2024年01月23日
    瀏覽(28)
  • vue3使用Vite打包報Rollup failed to resolve import “xxx/node_modules/ant-design-vue/xxxx

    在使用vue3 + vite + ant design vue 的時候,引入一些antd的一些組件的時候,通常運行是沒有錯的,但是打包會報錯,例如: Rollup failed to resolve import \\\"D:/xxxxx/node_modules/ant-design-vue/es/form-item-rest/style/index\\\" from \\\"src/views/xxx/xxx.vue\\\". 15:01:51 This is most likely unintended because it can break your applic

    2024年02月16日
    瀏覽(31)
  • html中如何用vue語法,并使用UI組件庫 ,html中引入vue+ant-design-vue或者vue+element-plus

    html中如何用vue語法,并使用UI組件庫 ,html中引入vue+ant-design-vue或者vue+element-plus

    前言 先說一下本次應用的場景,本次項目中,需要引入github中別人寫好的插件,插件比較大,沒有方法直接在自己項目中,把別人的項目打包合并生成html(類似于前端項目打包生成的 dist ),修改這里面的html,這種情況要么用原生js寫或者jquery還相對快一些,那為什么不直

    2024年02月10日
    瀏覽(28)
  • vue3+element-plus的后臺管理系統(tǒng)模板 和 vue3+ant-design-vue的后臺管理系統(tǒng)模板

    vue3+element-plus的后臺管理系統(tǒng)模板 和 vue3+ant-design-vue的后臺管理系統(tǒng)模板

    規(guī)范 :后臺系統(tǒng)模板,按照企業(yè)級別的規(guī)范搭建的。 權限控制 :通過后端返回的路由表(這個路由表是由前端這邊在系統(tǒng)配好的然后存儲在后端的)來動態(tài)渲染菜單和注冊路由,同時也根據(jù)頁面內(nèi)的接口權限對頁面中的按鈕做了是否可見的設置。前端這邊有 路由、角色、用

    2024年02月08日
    瀏覽(20)
  • ant-design-vue中upload上傳圖片、視頻實現(xiàn)預覽功能

    ant-design-vue中upload上傳圖片、視頻實現(xiàn)預覽功能

    有沒有小伙伴在使用ant-design-vue的upload組件時,發(fā)現(xiàn)api文檔在圖片預覽功能的介紹寥寥無幾,而且也沒提供視頻預覽的demo,在實際開發(fā)中碰到相應的需求直撓頭~~~~,別急,下面來給大家分享一個我自己封裝的upload組件,符合需求可以直接在項目中放到組件目錄調(diào)用。 templat

    2024年02月12日
    瀏覽(23)
  • 【ant-design-vue】實現(xiàn)table的拖拽排序(拖拽行和伸縮列):

    【ant-design-vue】實現(xiàn)table的拖拽排序(拖拽行和伸縮列):

    1.效果: 拖拽前: 拖拽后: 2.實現(xiàn): 3.出現(xiàn)的問題: 4.初始拖拽版本: 5.相關知識:

    2024年02月12日
    瀏覽(22)
  • 關于 ant-design-vue resetFields 失效

    關于 ant-design-vue resetFields 失效

    關于 ant-design-vue resetFields 失效 背景: 遇到這樣的問題使用 ant-design-vue useForm 來制作表單的時候, resetFields()失效 場景: 編輯 -賦值 新增 -初始值(問題點:新增的時候他就不 初始化 ) 方案: 1、調(diào)用 resetFields() 傳參 2、要么使用 reactive 明確定義初始值 解釋: 首先我這里講

    2024年01月17日
    瀏覽(23)
  • vue2+ant-design-vue a-select組件二次封裝(支持單選/多選添加全選/分頁(多選跨頁選中)/自定義label)

    vue2+ant-design-vue a-select組件二次封裝(支持單選/多選添加全選/分頁(多選跨頁選中)/自定義label)

    參數(shù) 說明 類型 默認值 v-model 綁定值 boolean / string / number/Array - mode 設置’multiple’\\\'tags’多選 (顯示全選) String - optionSource 下拉數(shù)據(jù)源 Array - width select寬度(可以設置百分比或px) String 100% customLabel 是否自定義設置下拉label String - valueKey 傳入的 option 數(shù)組中,要作為最終選擇

    2024年02月08日
    瀏覽(30)
  • ant-design-vue 自由切換 暗黑模式dark

    ant-design-vue 自由切換 暗黑模式dark

    思路 引入 dark.css 文件 動態(tài)切換 prefixCls 實現(xiàn)效果 我們來看看官網(wǎng)怎么說的 官網(wǎng)地址 除了 less 定制主題 外,我們還提供了 CSS Variable 版本以支持動態(tài)切換主題能力。你可以在 ConfigProvider 進行體驗。 調(diào)用 ConfigProvider 配置方法設置主題色: 默認情況下,CSS Variable 會以 --ant 作

    2023年04月21日
    瀏覽(21)

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

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

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

二維碼1

領取紅包

二維碼2

領紅包