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

Vue3 封裝 element-plus 圖標(biāo)選擇器

這篇具有很好參考價值的文章主要介紹了Vue3 封裝 element-plus 圖標(biāo)選擇器。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報違法"按鈕提交疑問。

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

效果一:

Vue3 封裝 element-plus 圖標(biāo)選擇器,前端,vue.js,javascript

效果二:

Vue3 封裝 element-plus 圖標(biāo)選擇器,前端,vue.js,javascript?

效果一的這個是把全部的icon圖標(biāo)都讓它顯示出來,讓我們自己選擇說選圖標(biāo)

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

2.1. 全局注冊 icon 組件

// main.ts
import App from './App.vue';
import { createApp } from 'vue';
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
 
const app = createApp(App);
 
// 全局掛載和注冊 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>

效果二的這個是渲染后端返回的icon圖標(biāo)文章來源地址http://www.zghlxwxcb.cn/news/detail-733765.html

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

3.1. 全局注冊 icon 組件

// main.ts
import App from './App.vue';
import { createApp } from 'vue';
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
 
const app = createApp(App);
 
// 全局掛載和注冊 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');

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

<template>
  <el-popover trigger="focus" :width="256">
    <template #reference>
      <el-button style="width: 100px" :icon="props.modelValue">{{ modelValue }}</el-button>
    </template>
    <div class="el-icon-picker">
      <component v-for="icon in props.fatherIcon" :key="icon.value"
                 :class="[icon.value, 'icon', { 'icon-active': icon.value == props.modelValue }]"
                 :is="icon.value"
                 @click="emits('update:modelValue', icon.value)">
      </component>
    </div>
  </el-popover>
</template>
<script lang="ts" setup>
 
interface Props {
  modelValue: string,
  fatherIcon: any[]
}
const props = defineProps<Props>();
 
console.log(props)
 
const emits = defineEmits(['update:modelValue']);
</script>
 
<style scoped>
.el-icon-picker {
  min-height: 20px;
  overflow-y: scroll;
  display: flex;
  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>

3.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="ic" :fatherIcon="icon"></ElIconPicker>
    </el-form-item>
  </el-form>
</template>

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

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

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

相關(guān)文章

  • vue3 vue.config.js配置Element-plus組件和Icon圖標(biāo)實(shí)現(xiàn)按需自動引入

    vue3 vue.config.js配置Element-plus組件和Icon圖標(biāo)實(shí)現(xiàn)按需自動引入

    打包時,報警告,提示包太大會影響性能 在頁面直接使用,直接使用 SVG 圖標(biāo),當(dāng)做一般的 svg 使用 icon使用時需要用以下兩種方式方式: 如果用在el-button里面的icon屬性上使用,用SVG方式無效,還是需要引入再使用(不知道有沒有其他方式) 注意: 使用 :icon=\\\"Edit\\\" 則icon的大

    2024年02月06日
    瀏覽(107)
  • 二、搭建前后端分離的自動化測試平臺的前端Vue3+Element-plus前端項(xiàng)目

    二、搭建前后端分離的自動化測試平臺的前端Vue3+Element-plus前端項(xiàng)目

    1、Node獲取地址 https://nodejs.org/en/download 一直默認(rèn)選項(xiàng)安裝,安裝好了之后,在環(huán)境變量中會自動配置Node的地址,可以在cmd中使用 node -v/npm -v命令驗(yàn)證是否下載成功 2、設(shè)置Node的配置內(nèi)容 (1)在安裝目錄下新建兩個文件夾命名為node_cache,和node_global: 其中 node_cache 是作為 緩

    2024年02月06日
    瀏覽(28)
  • Vue3 + TS + Element-Plus —— 項(xiàng)目系統(tǒng)中封裝表格+搜索表單 十分鐘寫五個UI不在是問題

    Vue3 + TS + Element-Plus —— 項(xiàng)目系統(tǒng)中封裝表格+搜索表單 十分鐘寫五個UI不在是問題

    前期回顧 純前端 —— 200行JS代碼、實(shí)現(xiàn)導(dǎo)出Excel、支持DIY樣式,縱橫合并-CSDN博客 https://blog.csdn.net/m0_57904695/article/details/135537511?spm=1001.2014.3001.5501 目錄 一、?????newTable.vue 封裝Table 二、?? newForm.vue 封裝搜索表單? 三、?? TS類型?srctypesglobal.d.ts 四、?? 頁面使用功能

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

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

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

    2024年02月02日
    瀏覽(123)
  • Vue3.2 + TypeScript + Pinia + Vite4 + Element-Plus + 微前端(qiankun) 后臺管理系統(tǒng)模板(已開源---顯示項(xiàng)目頁面截圖)

    Vue3.2 + TypeScript + Pinia + Vite4 + Element-Plus + 微前端(qiankun) 后臺管理系統(tǒng)模板(已開源---顯示項(xiàng)目頁面截圖)

    Wocwin-Admin,是基于 Vue3.2、TypeScript、Vite、Pinia、Element-Plus、Qiankun(微前端) 開源的一套后臺管理模板;同時集成了微前端 qiankun也可以當(dāng)做一個子應(yīng)用。項(xiàng)目中組件頁面使用了Element-plus 二次封裝 t-ui-plus 組件,目前已新增fastmock接口。 Link:https://wocwin.github.io/wocwin-admin/ 賬號:

    2024年02月08日
    瀏覽(40)
  • 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)入全部組件且注冊所有的圖標(biāo) 聲明使用 ElementPl

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

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

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

    2024年02月06日
    瀏覽(97)
  • vue3 element-plus 實(shí)現(xiàn)圖片預(yù)覽

    vue3 element-plus 實(shí)現(xiàn)圖片預(yù)覽

    element-plus下有這么一個組件 el-image-viewer /,但是這個組件是沒寫在文檔上面的,像普通組件一樣使用即可 可以通過點(diǎn)擊按鈕實(shí)現(xiàn)圖片預(yù)覽,而非el-image組件只能通過點(diǎn)擊圖片實(shí)現(xiàn)預(yù)覽 2.1封裝組件 2.3組件使用 在需要使用的地方引入,然后使用即可,這不是重點(diǎn),每個人使用的

    2024年02月15日
    瀏覽(28)
  • vue 基于element-plus el-button封裝按鈕組件

    封裝組件的原則是:組件只是數(shù)據(jù)流通的一個管道,不要糅合太多的邏輯在里面,是一個純組件,還要根據(jù)自己項(xiàng)目的業(yè)務(wù)場景做具體的處理。

    2024年02月10日
    瀏覽(21)
  • vue3+element-plus上傳文件,預(yù)覽文件

    vue3+element-plus上傳文件,預(yù)覽文件

    vue3+ts+element-plus上傳文件,預(yù)覽文件 場景:使用element-plus的el-upload標(biāo)簽,手動上傳文件,可預(yù)覽docx,xlsx,pdf,jpg,jpeg,png(本地資源以及網(wǎng)絡(luò)資源)。 1、使用el-upload標(biāo)簽 檢查上傳文件的文件格式與大小 上傳的附件信息在fileList中,組裝接口所需數(shù)據(jù)進(jìn)行上傳 使用docx-preview插件預(yù)覽

    2024年02月11日
    瀏覽(37)

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

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

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

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包