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

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

這篇具有很好參考價值的文章主要介紹了vue3 vue.config.js配置Element-plus組件和Icon圖標實現(xiàn)按需自動引入。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

打包時,報警告,提示包太大會影響性能

1.配置前包體積:

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

2.安裝插件:

npm i unplugin-auto-import unplugin-vue-components unplugin-icons -D

3.vue.config.js中加入以下配置:

const { defineConfig } = require('@vue/cli-service')

const AutoImport = require('unplugin-auto-import/webpack')
const Components = require('unplugin-vue-components/webpack')
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')
const Icons = require('unplugin-icons/webpack')
const IconsResolver = require('unplugin-icons/resolver')

module.exports = defineConfig({
   ...
    configureWebpack: {
        plugins: [
            //配置webpack自動按需引入element-plus,
            require('unplugin-element-plus/webpack')({
                libs: [{
                    libraryName: 'element-plus',
                    esModule: true,
                    resolveStyle: (name) => {
                        return `element-plus/theme-chalk/${name}.css`
                    },
                }, ]
            }),
            AutoImport({
                resolvers: [
                    // 自動導入圖標組件
                    IconsResolver({
                        prefix: 'Icon',
                    }),
                    ElementPlusResolver()
                ]
            }),
            Components({
                resolvers: [
                    // 自動注冊圖標組件
                    IconsResolver({
                        enabledCollections: ['ep'],
                    }),
                    ElementPlusResolver()
                ]
            }),
            Icons({
                autoInstall: true,
            }),
        ],
    },

})

4.使用

在頁面直接使用,直接使用 SVG 圖標,當做一般的 svg 使用
icon使用時需要用以下兩種方式方式:

<el-icon> 
    <i-ep-edit/> 
</el-icon>
<i-ep-edit/>

5.在el-button中使用

如果用在el-button里面的icon屬性上使用,用SVG方式無效,還是需要引入再使用(不知道有沒有其他方式)

import { Delete, Edit } from '@element-plus/icons-vue'
<el-button type="success" size="small" :icon="Edit" round @click="openAddUserForm('add')">新增用戶</el-button>

注意:

使用:icon="Edit"則icon的大小和button里面字體大小一致size=small
但是如果使用<i-ep-search/>放在el-button里面,則會比放在button里大
<el-button type="primary" size="small" @click="searchResource"><i-ep-search/>查詢</el-button>

6.按需引入后,ElMessageBox樣式錯亂

解決方法一:在當前頁面或者全局main.js里面引入import "element-plus/es/components/message-box/style/css";即可,但是違背了按需引入的初衷

解決方法二按需導入:?使用unplugin-element-plus對使用到的組件樣式進行按需導入?

npm i unplugin-element-plus -D

然后再vue.config.js中配置以下即可:

 plugins: [
            //配置webpack自動按需引入element-plus,
            require('unplugin-element-plus/webpack')({
                libs: [{
                    libraryName: 'element-plus',
                    esModule: true,
                    resolveStyle: (name) => {
                        return `element-plus/theme-chalk/${name}.css`
                    },
                }, ]
            }),
....
]

7.使用按需導入后,使用配置文件自動化生成表單中,配置得icon:'Edit'失效

全局引入時,直接使用icon: 'Edit',然后jsx中直接讀取即可

buttons: [{
            name: '生成案例',
            title: 'generateTestCase',
            type: 'primary',
            size: 'default', //可以是default,small,large
            icon: 'Edit',
            // 按鈕是否為樸素類型
            // plain: true,
            onClick: null
        }
]
  const Button = (form, data) =>(
    !data.isHidden?<ElButton
        type={data.type}
        size={data.size}
        icon= {data.icon}
        plain={data.plain}
        onClick={data.onClick}
        >
          {data.name}</ElButton>:''
  )

?但是按需引入后,這樣做失效了。

解決:直接把icon: shallowRef(Edit)或者markRaw(Edit),然后引入組件即可

import { DocumentDelete, Edit, Download } from '@element-plus/icons-vue'
import { shallowRef } from 'vue'

 buttons: [{
            name: '生成案例',
            title: 'generateTestCase',
            type: 'primary',
            size: 'default', //可以是default,small,large
            icon: shallowRef(Edit),
            // 按鈕是否為樸素類型
            // plain: true,
            onClick: null
        }]

注意:使用組件時,必須使用shallowRef或者?markRaw對組件進行包裝,否則會報警告

[Vue warn]: Vue received a Component which was made a reactive object. This can lead to unnecessary performance overhead, and should be avoided by marking the component with `markRaw` or using `shallowRef` instead of `ref`. 
Component that was made reactive:  {name: "DocumentDelete", __file: "document-delete.vue", render: ?} 

報錯原因:vue接收到一個組件,該組件是一個響應式對象。這可能會導致不必要的性能開銷,應該通過使用’markRaw‘或使用’shallowRef‘而不是’ref'來避免。
寫成:shallowRef(Edit)或者markRaw(Edit)即可?

8.其他打包警告

警告:
chunk 574 [mini-css-extract-plugin]
Conflicting order. Following module has been added:

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

解決:由于各個css和js文件引入順序問題導致

module.exports = defineConfig({
......
    css: {
        extract: {
            ignoreOrder: true
        }
    }
})

9.配置后包體積大小

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

?文章來源地址http://www.zghlxwxcb.cn/news/detail-462386.html

到了這里,關于vue3 vue.config.js配置Element-plus組件和Icon圖標實現(xiàn)按需自動引入的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!

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

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

相關文章

  • vue3+element-plus組件下拉列表,數(shù)組數(shù)據(jù)轉(zhuǎn)成樹形數(shù)據(jù)

    引入組件 可以直接在項目中引入element-plus表格組件,如果需要變成下拉列表樣式需要添加以下屬性: row-key 必填 最好給數(shù)字或唯一屬性 , 給每個節(jié)點設置id 不填的話 沒有辦法實現(xiàn)展開效果 load 這個是動態(tài)添加數(shù)據(jù)的 前提(開啟lazy ,表格數(shù)組里設置了hasChildren:true) tre

    2024年02月13日
    瀏覽(48)
  • vue3項目搭建并配置element-plus

    安裝完成后,輸入如下指令查看vue的版本: 選擇一個要存放項目的目錄,打開小黑窗輸入如下命令: 一開始輸入項目名稱或者默認vue-project,然后根據(jù)需求選擇Yes/No 生成完項目后,輸入如下指令: src/main.js里引入 index.css的文件位置根據(jù)實際情況寫,也有可能是 const app后面加

    2024年02月13日
    瀏覽(30)
  • vue-treeselect(適配Vue3.2)及Element-plus的TreeSelect組件

    1.1、vue2 使用的版本 官網(wǎng)地址:https://www.npmjs.com/package/@riophae/vue-treeselect 是3年前更新的 安裝: 如果你的項目是vue3的話,使用該安裝命令會提示,此命令只針對vue2.2版本 具體提示內(nèi)容是: peerDependencies WARNING @riophae/vue-treeselect@latest requires a peer of vue@^2.2.0 but vue@3.2.39 was instal

    2024年02月15日
    瀏覽(25)
  • Vue3+Element-Plus中的Tree組件,多選時的賦值與取值

    el-tree 是 element-ui 提供的一個樹形組件,可以在 Vue.js 應用中使用。el-tree 組件提供了 getCheckedNodes 方法,可以用來獲取樹形結構中被選中的節(jié)點。

    2024年02月14日
    瀏覽(28)
  • 【Vue3 博物館管理系統(tǒng)】使用Vue3、Element-plus菜單組件構建前臺用戶菜單

    【Vue3 博物館管理系統(tǒng)】使用Vue3、Element-plus菜單組件構建前臺用戶菜單

    第一章 定制上中下(頂部菜單、底部區(qū)域、中間主區(qū)域顯示)三層結構首頁 第二章 使用Vue3、Element-plus菜單組件構建菜單 [第三章 使用Vue3、Element-plus菜單組件構建輪播圖] [第四章 使用Vue3、Element-plus菜單組件構建組圖文章] 上一章節(jié)給我們把博物館管理系統(tǒng)打了個地基,基本

    2024年02月13日
    瀏覽(36)
  • Vue3自動引入組件(unplugin-auto-import和element-plus)

    在使用 Vue3 開發(fā)項目時,我們經(jīng)常需要引入多個組件,但是每次手動引入非常麻煩,容易出錯。為了解決這個問題,我們可以使用 unplugin-auto-import 插件自動引入組件,提高開發(fā)效率。本篇博客將詳細介紹如何在 Vue3 項目中使用 unplugin-auto-import 插件。 首先,在項目中安裝 un

    2024年02月13日
    瀏覽(30)
  • vue3使用element-plus 樹組件(el-tree)數(shù)據(jù)回顯

    html搭建結構 js 非常好用,拿過來修改一下check事件,ref獲取就直接可以使用了?

    2024年04月09日
    瀏覽(99)
  • [Vue3 博物館管理系統(tǒng)] 使用Vue3、Element-plus tabs組件構建選項卡功能

    [Vue3 博物館管理系統(tǒng)] 使用Vue3、Element-plus tabs組件構建選項卡功能

    第一章 定制上中下(頂部菜單、底部區(qū)域、中間主區(qū)域顯示)三層結構首頁 第二章 使用Vue3、Element-plus菜單組件構建菜單 第三章 使用Vue3、Element-plus走馬燈組件構建輪播圖 第四章 使用Vue3、Element-plus tabs組件構建選項卡功能 [第五章 使用Vue3、Element-plus菜單組件構建組圖文章

    2024年02月09日
    瀏覽(34)
  • 沉淀自己的pro-table組件,并發(fā)布到npm(Vue3、element-plus)

    傳送門 約定:npm包名 vue3-el-pro-table ,引用 vue3-el-pro-table 的包名為“本項目”。 聲明: Vue3ProTable.vue 代碼是在這個項目的基礎上進行修改的。 作者:hans774882968以及hans774882968以及hans774882968 Quick Start src/main.ts Then use vue3-pro-table / directly in .vue file. Import interface: Component props defi

    2024年02月16日
    瀏覽(58)
  • vue3+ts+element-plus 之使用node.js對接mysql進行表格數(shù)據(jù)展示

    vue3+ts+element-plus 之使用node.js對接mysql進行表格數(shù)據(jù)展示

    * 初始化node 查看node是否安裝 node -v 初始化命令 npm init 初始化配置解釋如下: 完成后會有一個package.json文件 * 安裝可能用到的依賴 根據(jù)需求安裝,我這里需要對接mysql,安裝依賴 ,我是一次性安裝完,后邊會直接使用,也可以邊安裝邊使用。如下 安裝成功如下: * 配置文件

    2024年02月15日
    瀏覽(54)

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

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

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

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

二維碼1

領取紅包

二維碼2

領紅包