国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

目錄
vite-plugin-svg-icons
首頁 web前端 Vue.js 深入淺析vue3 vite中怎么使用svg圖標(biāo)

深入淺析vue3 vite中怎么使用svg圖標(biāo)

Apr 28, 2022 am 10:48 AM
vue svg vue3 vite

svg圖片在項(xiàng)目中使用的非常廣泛,下面本篇文章帶大家介紹一下如何在vue3 vite 中使用svg圖標(biāo),希望對大家有所幫助!

深入淺析vue3 vite中怎么使用svg圖標(biāo)

vite-plugin-svg-icons

  • 預(yù)加載?在項(xiàng)目運(yùn)行時(shí)就生成所有圖標(biāo),只需操作一次 dom
  • 高性能?內(nèi)置緩存,僅當(dāng)文件被修改時(shí)才會重新生成

(學(xué)習(xí)視頻分享:vuejs教程

安裝

node version: ?>=12.0.0 vite version: ?>=2.0.0

yarn add vite-plugin-svg-icons -D
# or
npm i vite-plugin-svg-icons -D
# or
pnpm install vite-plugin-svg-icons -D

使用

  • vite.config.ts 中的配置插件
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import path from 'path'

export default () => {
  return {
    plugins: [
      createSvgIconsPlugin({
        // 指定需要緩存的圖標(biāo)文件夾
        iconDirs: [path.resolve(process.cwd(), 'src/icons')],
        // 指定symbolId格式
        symbolId: 'icon-[dir]-[name]',

        /**
         * 自定義插入位置
         * @default: body-last
         */
        // inject?: 'body-last' | 'body-first'

        /**
         * custom dom id
         * @default: __svg__icons__dom__
         */
        // customDomId: '__svg__icons__dom__',
      }),
    ],
  }
}
  • 在 src/main.js 內(nèi)引入注冊腳本
import 'virtual:svg-icons-register'

如何在組件中使用

  • 創(chuàng)建SvgIcon組件

/src/components/SvgIcon/index.vue

<template>
  <svg aria-hidden="true" class="svg-icon" :width="props.size" :height="props.size">
    <use :xlink:href="symbolId" :fill="props.color" />
  </svg>
</template>

<script setup>
import { computed } from &#39;vue&#39;
const props = defineProps({
  prefix: {
    type: String,
    default: &#39;icon&#39;
  },
  name: {
    type: String,
    required: true
  },
  color: {
    type: String,
    default: &#39;#333&#39;
  },
  size: {
    type: String,
    default: &#39;1em&#39;
  }
})

const symbolId = computed(() => `#${props.prefix}-${props.name}`)
</script>
  • icons目錄結(jié)構(gòu)

# src/icons

- icon1.svg
- icon2.svg
- icon3.svg
- dir/icon1.svg
  • 全局注冊組件

# src/main.js

import { createApp } from 'vue'
import App from './App.vue'
import router from './router'

import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'

import svgIcon from "@/components/SvgIcon/index.vue";
import &#39;virtual:svg-icons-register&#39;

createApp(App)
    .use(ElementPlus)
    .use(router)
    .component('svg-icon', svgIcon)
    .mount('#app')
  • 頁面使用

<template>
    <svg-icon v-if="props.icon" :name="props.icon" />
    <span v-if="props.title" slot=&#39;title&#39;>{{ props.title }}</span>
</template>

<script setup>

const props = defineProps({
    icon: {
        type: String,
        default: &#39;&#39;
    },
    title: {
        type: String,
        default: &#39;&#39;
    }
})
</script>

獲取所有 SymbolId

import ids from &#39;virtual:svg-icons-names&#39;
// => [&#39;icon-icon1&#39;,&#39;icon-icon2&#39;,&#39;icon-icon3&#39;]

(學(xué)習(xí)視頻分享:web前端開發(fā)、編程入門

以上是深入淺析vue3 vite中怎么使用svg圖標(biāo)的詳細(xì)內(nèi)容。更多信息請關(guān)注PHP中文網(wǎng)其他相關(guān)文章!

本站聲明
本文內(nèi)容由網(wǎng)友自發(fā)貢獻(xiàn),版權(quán)歸原作者所有,本站不承擔(dān)相應(yīng)法律責(zé)任。如您發(fā)現(xiàn)有涉嫌抄襲侵權(quán)的內(nèi)容,請聯(lián)系admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費(fèi)脫衣服圖片

Undresser.AI Undress

Undresser.AI Undress

人工智能驅(qū)動的應(yīng)用程序,用于創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用于從照片中去除衣服的在線人工智能工具。

Clothoff.io

Clothoff.io

AI脫衣機(jī)

Video Face Swap

Video Face Swap

使用我們完全免費(fèi)的人工智能換臉工具輕松在任何視頻中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費(fèi)的代碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

功能強(qiáng)大的PHP集成開發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級代碼編輯軟件(SublimeText3)

vue怎么給按鈕添加函數(shù) vue怎么給按鈕添加函數(shù) Apr 08, 2025 am 08:51 AM

可以通過以下步驟為 Vue 按鈕添加函數(shù):將 HTML 模板中的按鈕綁定到一個(gè)方法。在 Vue 實(shí)例中定義該方法并編寫函數(shù)邏輯。

React與Vue:Netflix使用哪個(gè)框架? React與Vue:Netflix使用哪個(gè)框架? Apr 14, 2025 am 12:19 AM

NetflixusesAcustomFrameworkcalled“ Gibbon” BuiltonReact,notReactorVueDirectly.1)TeamExperience:selectBasedAsedonFamiliarity.2)ProjectComplexity:vueforsimplerprojects,vueforsimplerprojects,reactforforforecomplexones.3)cocatizationNeedsneeds:reactofficatizationneedneeds:reactofferizationneedneedneedneeds:reactoffersizatization needeffersefersmoreflexiblesimore.4)ecosyaka

Netflix的前端:React(或VUE)的示例和應(yīng)用 Netflix的前端:React(或VUE)的示例和應(yīng)用 Apr 16, 2025 am 12:08 AM

Netflix使用React作為其前端框架。1)React的組件化開發(fā)模式和強(qiáng)大生態(tài)系統(tǒng)是Netflix選擇它的主要原因。2)通過組件化,Netflix將復(fù)雜界面拆分成可管理的小塊,如視頻播放器、推薦列表和用戶評論。3)React的虛擬DOM和組件生命周期優(yōu)化了渲染效率和用戶交互管理。

vue的div怎么跳轉(zhuǎn) vue的div怎么跳轉(zhuǎn) Apr 08, 2025 am 09:18 AM

Vue 中 div 元素跳轉(zhuǎn)的方法有兩種:使用 Vue Router,添加 router-link 組件。添加 @click 事件監(jiān)聽器,調(diào)用 this.$router.push() 方法跳轉(zhuǎn)。

反應(yīng),vue和Netflix前端的未來 反應(yīng),vue和Netflix前端的未來 Apr 12, 2025 am 12:12 AM

Netflix主要使用React作為前端框架,輔以Vue用于特定功能。1)React的組件化和虛擬DOM提升了Netflix應(yīng)用的性能和開發(fā)效率。2)Vue在Netflix的內(nèi)部工具和小型項(xiàng)目中應(yīng)用,其靈活性和易用性是關(guān)鍵。

vue怎么a標(biāo)簽跳轉(zhuǎn) vue怎么a標(biāo)簽跳轉(zhuǎn) Apr 08, 2025 am 09:24 AM

實(shí)現(xiàn) Vue 中 a 標(biāo)簽跳轉(zhuǎn)的方法包括:HTML 模板中使用 a 標(biāo)簽指定 href 屬性。使用 Vue 路由的 router-link 組件。使用 JavaScript 的 this.$router.push() 方法??赏ㄟ^ query 參數(shù)傳遞參數(shù),并在 router 選項(xiàng)中配置路由以進(jìn)行動態(tài)跳轉(zhuǎn)。

vue怎么實(shí)現(xiàn)組件跳轉(zhuǎn) vue怎么實(shí)現(xiàn)組件跳轉(zhuǎn) Apr 08, 2025 am 09:21 AM

Vue 中實(shí)現(xiàn)組件跳轉(zhuǎn)有以下方法:使用 router-link 和 &lt;router-view&gt; 組件進(jìn)行超鏈接跳轉(zhuǎn),指定 :to 屬性為目標(biāo)路徑。直接使用 &lt;router-view&gt; 組件顯示當(dāng)前路由渲染的組件。使用 router.push() 和 router.replace() 方法進(jìn)行程序化導(dǎo)航,前者保存歷史記錄,后者替換當(dāng)前路由不留記錄。

怎樣開發(fā)一個(gè)完整的PythonWeb應(yīng)用程序? 怎樣開發(fā)一個(gè)完整的PythonWeb應(yīng)用程序? May 23, 2025 pm 10:39 PM

要開發(fā)一個(gè)完整的PythonWeb應(yīng)用程序,應(yīng)遵循以下步驟:1.選擇合適的框架,如Django或Flask。2.集成數(shù)據(jù)庫,使用ORM如SQLAlchemy。3.設(shè)計(jì)前端,使用Vue或React。4.進(jìn)行測試,使用pytest或unittest。5.部署應(yīng)用,使用Docker和平臺如Heroku或AWS。通過這些步驟,可以構(gòu)建出功能強(qiáng)大且高效的Web應(yīng)用。

See all articles