最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue+Element UI實(shí)現(xiàn)下拉菜單的封裝

 更新時(shí)間:2021年09月22日 16:36:22   作者:似曾不相識(shí)  
這篇文章主要為大家詳細(xì)介紹了Vue+Element UI實(shí)現(xiàn)下拉菜單的封裝代碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Vue+Element UI實(shí)現(xiàn)下拉菜單封裝的具體代碼,供大家參考,具體內(nèi)容如下

1、效果圖

先貼個(gè)效果圖,菜單項(xiàng)沒(méi)有做樣式美化,圖中顯示的邊框也是沒(méi)有的(邊框是外部容器的邊框),其它的根據(jù)需要自己修改一下樣式即可。

2、組件封裝

組件的封裝用到了CSS動(dòng)畫、定位,以及Element UI提供的下拉菜單組件el-dropdown,代碼如下

<template>
  <div class="all" @click="clickFire">
    <span class="item-border">
      <el-image
        class="item"
        style="width: 24px; height: 24px"
        fit="cover"
        :lazy="isLazy"
        :src="itemProperty.url"
        :title="itemProperty.name"
        :placeholder="itemProperty.name"
      ></el-image>
    </span>
    <div class="wrap-item"></div>
    <!-- 下拉菜單 -->
    <el-dropdown class="dropMenu" @command="handleCommand">
      <span class="el-dropdown-link" v-text="itemProperty.name"></span>
      <el-dropdown-menu slot="dropdown" class="dropMenuitems">
        <!-- <el-dropdown-item>黃金糕</el-dropdown-item>
        <el-dropdown-item>獅子頭</el-dropdown-item>
        <el-dropdown-item>螺螄粉</el-dropdown-item> -->
        <el-dropdown-item
          class="dropMenu-item"
          v-for="(item, index) in itemProperty.menus"
          :key="index"
          :command="item"
          >{{ item }}</el-dropdown-item
        >
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>
<script>
export default {
  props: {
    itemProperty: Object,
    require: true,
  },
  data() {
    return {
      isLazy: true,
      item: {
        name: 'item',
        url: require('../../../static/imgs/menus/warning.png'),
        menus: [
          'submenu-1',
          'submenu-2',
          'submenu-3',
          'submenu-4',
          'submenu-5',
        ],
      },
    }
  },
  mounted() {
    this.$data.item = this.$props.itemProperty
    // console.log(this.$props.itemProperty)
  },
  methods: {
    //父級(jí)圖標(biāo)點(diǎn)擊事件
    clickFire() {
      //參數(shù)1:自定義組件事件,在父組件中被調(diào)用才能觸發(fā)父子組件的值傳遞;參數(shù)2:向父組件傳遞的數(shù)據(jù)[可為數(shù)組形式]
      this.$emit('clickItem', this.$data.item)
    },
    //下拉菜單點(diǎn)擊事件
    handleCommand(command) {
      // console.log(command)
      this.$emit('handleCommand', command)
    },
  },
}
</script>
<style lang="less" scoped>
.all {
  // border: 1px solid skyblue;
  display: inline-block;
  position: relative;
  width: 65px;
  height: 65px;
  // overflow: hidden;
}
// 最內(nèi)層
.item-border {
  display: inline-block;
  margin: 0 auto;
  margin-left: 0px;
  margin-top: 10px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid skyblue;
  // background-color: slateblue;
  .item {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }
}

// 最外層
.wrap-item {
  position: absolute;
  top: 0;
  left: 0;
  display: inline-block;
  width: 56px;
  height: 56px;
  border: 5px dotted transparent;
  border-left: 5px dotted #73ffff;
  border-left-width: 3px;
  border-right-color: #73ffff;
  border-top-color: transparent;
  border-radius: 50%;
  // background-color: burlywood;
  animation: circle 3s infinite linear;
}
@keyframes circle {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(-360deg);
  }
}
//下拉菜單
.dropMenu {
  margin-top: 5px;
  // background-color: yellowgreen;
  color: #fff;
  //標(biāo)題項(xiàng)
  .el-dropdown-link {
    cursor: pointer;
  }
  //菜單子項(xiàng)
  .el-dropdown-menu__item {
    color: red !important;
  }
  .dropMenu-item {
    background-color: rosybrown;
  }
}
</style>

3、父組件中使用舉例

<template>
    <!-- 功能模塊:使用子組件-注意自定義事件clickItem與handleCommand -->
    <div class="funcModules">
      <RingItem
        class="ringitem-style"
        v-for="(item, index) in funcItems"
        :key="index"
        :itemProperty="item"
        @clickItem="clickRingItem"
        @handleCommand="handleCommandDropMenu"
      />
    </div>
</template>
<script>
//1-導(dǎo)入子組件
import RingItem from '../Controls/RingItem'
export default {
  components: {
  //2-注冊(cè)組件
    RingItem,
  },
  data() {
    return {
      //功能模塊圖標(biāo)資源
      funcItems: [
        {
          name: '系統(tǒng)管理',
          url: require('../../../static/imgs/menus/management.png'),
          menus: ['細(xì)則管理', '關(guān)于我們'],
        },
      ],
    }
  },
  methods: {
    /**
     * RingItem子組件點(diǎn)擊事件:value是子組件中通過(guò)emit傳遞的值
     */
    clickRingItem(value) {
      //判斷子組件的name屬性值,實(shí)現(xiàn)相應(yīng)的業(yè)務(wù)邏輯
      switch (value.name) {
        case '系統(tǒng)管理': {
          console.log('系統(tǒng)管理')
          //執(zhí)行頁(yè)面跳轉(zhuǎn)-管理中心(看自己的需求,添加業(yè)務(wù)邏輯)
          //this.$router.push({ path: '/admincenter' })
          break
        }
      }
    },
    /**
     * RingItem子組件:下拉菜單點(diǎn)擊事件(value是子組件中通過(guò)emit傳遞的值)
     */
    handleCommandDropMenu(value) {
      console.log(value)
       switch (value.name) {
        case '細(xì)則管理': {
          console.log('系統(tǒng)管理')
          //執(zhí)行頁(yè)面跳轉(zhuǎn)-管理中心(看自己的需求,添加業(yè)務(wù)邏輯)
          //this.$router.push({ path: '/admincenter' })
          break
        }
         case '關(guān)于我們': {
          console.log('系統(tǒng)管理')
          //執(zhí)行頁(yè)面跳轉(zhuǎn)-管理中心(看自己的需求,添加業(yè)務(wù)邏輯)
          //this.$router.push({ path: '/admincenter' })
          break
        }
      }
    },
  },
}
</script>
<style lang="less" scoped>
//樣式調(diào)整
</style>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue按鈕權(quán)限的實(shí)現(xiàn)示例

    Vue按鈕權(quán)限的實(shí)現(xiàn)示例

    在編寫Vue代碼的時(shí)候,經(jīng)常會(huì)碰到各種權(quán)限問(wèn)題,本文主要介紹了Vue按鈕權(quán)限的實(shí)現(xiàn)示例,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-08-08
  • Vue中EpicEditor和vue-quill-editor的使用詳解

    Vue中EpicEditor和vue-quill-editor的使用詳解

    EpicEditor和Vue-quill-editor都是基于Quill.js的富文本編輯器,并且都提供了許多強(qiáng)大的功能,下面我們就來(lái)介紹一下二者的具體使用,感興趣的小伙伴可以了解一下
    2023-11-11
  • vue3+vite配置多頁(yè)面的示例代碼

    vue3+vite配置多頁(yè)面的示例代碼

    通過(guò)配置多頁(yè)面應(yīng)用,從而將給子模塊依賴分隔開(kāi)各自加載,可以減少初始資源的請(qǐng)求,加快頁(yè)面的訪問(wèn)速度,這篇文章主要介紹了vue3+vite配置多頁(yè)面的詳細(xì)過(guò)程,需要的朋友可以參考下
    2023-06-06
  • vue中v-bind和v-model的區(qū)別及說(shuō)明

    vue中v-bind和v-model的區(qū)別及說(shuō)明

    這篇文章主要介紹了vue中v-bind和v-model的區(qū)別及說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-08-08
  • vue3中使用ant-design-vue的layout組件實(shí)現(xiàn)動(dòng)態(tài)導(dǎo)航欄和面包屑功能

    vue3中使用ant-design-vue的layout組件實(shí)現(xiàn)動(dòng)態(tài)導(dǎo)航欄和面包屑功能

    這篇文章主要介紹了vue3中使用ant-design-vue的layout組件實(shí)現(xiàn)動(dòng)態(tài)導(dǎo)航欄和面包屑功能,基于一個(gè)新建的Vue3項(xiàng)目上實(shí)現(xiàn),本文結(jié)合示例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2023-01-01
  • vue3中addEventListener的用法詳解

    vue3中addEventListener的用法詳解

    vue3中定義全局指令時(shí),往往會(huì)碰到一個(gè)問(wèn)題:事件無(wú)法解綁,為什么會(huì)這樣,因?yàn)橥ǔT谥噶畹膍ounted鉤子中綁定事件,事件處理函數(shù)也定義在mounted中,本文講給大家講講vue3中addEventListener的妙用,需要的朋友可以參考下
    2023-08-08
  • vue data有值,但是頁(yè)面{{}} 取不到值的解決

    vue data有值,但是頁(yè)面{{}} 取不到值的解決

    這篇文章主要介紹了vue data有值,但是頁(yè)面{{}} 取不到值的解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-11-11
  • 快速解決vue-cli在ie9+中無(wú)效的問(wèn)題

    快速解決vue-cli在ie9+中無(wú)效的問(wèn)題

    今天小編就為大家分享一篇快速解決vue-cli在ie9+中無(wú)效的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-09-09
  • Vue3?Reactive響應(yīng)式原理邏輯詳解

    Vue3?Reactive響應(yīng)式原理邏輯詳解

    這篇文章主要介紹了Vue3?Reactive響應(yīng)式原理邏輯詳解,文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-07-07
  • vue.js配合$.post從后臺(tái)獲取數(shù)據(jù)簡(jiǎn)單demo分享

    vue.js配合$.post從后臺(tái)獲取數(shù)據(jù)簡(jiǎn)單demo分享

    今天小編就為大家?guī)?lái)一篇vue.js配合$.post從后臺(tái)獲取數(shù)據(jù)簡(jiǎn)單demo分享,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-08-08

最新評(píng)論

柘城县| 孟津县| 武定县| 平度市| 凯里市| 同心县| 随州市| 荣昌县| 合肥市| 凤阳县| 榆中县| 香港| 寻甸| 本溪| 高雄市| 怀柔区| 南投市| 望城县| 古丈县| 尚志市| 蓬溪县| 台前县| 海阳市| 昌黎县| 通海县| 罗平县| 宁都县| 长白| 富民县| 莱芜市| 普洱| 阜宁县| 广汉市| 安多县| 东乡族自治县| 龙南县| 南江县| 贡嘎县| 乐山市| 曲靖市| 庆阳市|