欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Vue3 封裝 element-plus 圖標(biāo)選擇器實(shí)現(xiàn)步驟

 更新時(shí)間:2023年09月19日 09:56:32   作者:大可-  
這篇文章主要介紹了Vue3 封裝 element-plus 圖標(biāo)選擇器,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

一、實(shí)現(xiàn)效果

二、實(shí)現(xiàn)步驟

2.1. 全局注冊(cè) icon 組件

// main.ts
import App from './App.vue';
import { createApp } from 'vue';
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
const app = createApp(App);
// 全局掛載和注冊(cè) element-plus 的所有 icon
app.config.globalProperties.$icons = []
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.config.globalProperties.$icons.push(key)
    app.component(key, component)
}
app.mount('#app');

2.2. 組件實(shí)現(xiàn)

<script setup lang="ts">
import { ComponentInternalInstance, defineEmits, defineProps, getCurrentInstance } from 'vue'
const { appContext: {app: { config: { globalProperties } } } } = getCurrentInstance() as ComponentInternalInstance
interface Props {
  modelValue: string
}
const props = defineProps<Props>()
const emits = defineEmits(['update:modelValue'])
</script>
<template>
  <el-popover trigger="focus" :width="256">
    <template #reference>
      <el-button :icon="modelValue">{{ modelValue }}</el-button>
    </template>
    <div class="el-icon-picker">
      <component v-for="icon in globalProperties.$icons" :key="icon"
        :class="[icon, 'icon', { 'icon-active': icon == modelValue }]"
        :is="icon"
        @click="emits('update:modelValue', icon)">
      </component>
    </div>
  </el-popover>
</template>
<style scoped>
.el-icon-picker {
  height: 256px;
  overflow-y: scroll;
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
}
.icon {
  display: inline-block;
  width: 24px;
  height: 24px;
  color: var(--el-text-color-regular);
  font-size: 20px;
  border-radius: 4px;
  cursor: pointer;
  text-align: center;
  line-height: 45px;
  margin: 5px;
}
.icon:hover {
  color: var(--el-color-primary);
}
.icon-active {
  color: var(--el-color-primary);
}
</style>

2.3. 使用

<script setup lang="ts">
import { ref } from 'vue';
import ElIconPicker from './components/el-icon-picker.vue';
const icon = ref<string>('');
</script>
<template>
  <el-form>
    <el-form-item label="圖標(biāo)">
      <ElIconPicker v-model="icon"></ElIconPicker>
    </el-form-item>
  </el-form>
</template>

到此這篇關(guān)于Vue3 封裝 element-plus 圖標(biāo)選擇器的文章就介紹到這了,更多相關(guān)Vue3 element-plus 圖標(biāo)選擇器內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • vue登錄以及權(quán)限驗(yàn)證相關(guān)的實(shí)現(xiàn)

    vue登錄以及權(quán)限驗(yàn)證相關(guān)的實(shí)現(xiàn)

    這篇文章主要介紹了vue登錄以及權(quán)限驗(yàn)證相關(guān)的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-10-10
  • vue props 一次傳多個(gè)值實(shí)例

    vue props 一次傳多個(gè)值實(shí)例

    這篇文章主要介紹了vue props 一次傳多個(gè)值實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-07-07
  • 使用vue-cli搭建SPA項(xiàng)目的詳細(xì)過程

    使用vue-cli搭建SPA項(xiàng)目的詳細(xì)過程

    vue-cli是vue.js的腳手架,用于自動(dòng)生成vue.js+webpack的項(xiàng)目模板,本文通過實(shí)例代碼給大家介紹vue-cli搭建SPA項(xiàng)目的詳細(xì)過程,感興趣的朋友跟隨小編一起看看吧
    2022-09-09
  • vue實(shí)現(xiàn)子路由調(diào)用父路由的方法

    vue實(shí)現(xiàn)子路由調(diào)用父路由的方法

    這篇文章主要介紹了vue實(shí)現(xiàn)子路由調(diào)用父路由的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-06-06
  • vue使用原生js創(chuàng)建元素樣式不生效問題及解決

    vue使用原生js創(chuàng)建元素樣式不生效問題及解決

    這篇文章主要介紹了vue使用原生js創(chuàng)建元素樣式不生效問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-06-06
  • Vue 瑩石攝像頭直播視頻實(shí)例代碼

    Vue 瑩石攝像頭直播視頻實(shí)例代碼

    本文通過實(shí)例代碼給大家介紹了vue 瑩石攝像頭直播視頻功能,文章還給大家提到了vue h5項(xiàng)目調(diào)用手機(jī)攝像頭錄像并上傳的功能,需要的朋友可以參考下
    2018-08-08
  • 使用Elemen加上lang=“ts“后編譯報(bào)錯(cuò)

    使用Elemen加上lang=“ts“后編譯報(bào)錯(cuò)

    本文主要介紹了使用Elemen加上lang=“ts“后編譯報(bào)錯(cuò),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-04-04
  • vue之Vue.use的使用場(chǎng)景及說明

    vue之Vue.use的使用場(chǎng)景及說明

    這篇文章主要介紹了vue之Vue.use的使用場(chǎng)景,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • Vue父子模版?zhèn)髦导敖M件傳值的三種方法

    Vue父子模版?zhèn)髦导敖M件傳值的三種方法

    這篇文章主要介紹了Vue父子模版?zhèn)髦导敖M件傳值的三種方法,需要的朋友可以參考下
    2017-11-11
  • 說說Vuex的getters屬性的具體用法

    說說Vuex的getters屬性的具體用法

    這篇文章主要介紹了說說Vuex的getters屬性的具體用法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2019-04-04

最新評(píng)論