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

vue3 集成 Element-Plus之全局導(dǎo)入/按需導(dǎo)入

這篇具有很好參考價(jià)值的文章主要介紹了vue3 集成 Element-Plus之全局導(dǎo)入/按需導(dǎo)入。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

element-plus集成

Element Plus,一套為開發(fā)者、設(shè)計(jì)師和產(chǎn)品經(jīng)理準(zhǔn)備的基于 Vue 3.0 的桌面端組件庫(kù):

  • 在Vue2中使用element-ui,而element-plus是element-ui針對(duì)于vue3開發(fā)的一個(gè)UI組件庫(kù);
  • 它的使用方式和很多其他的組件庫(kù)是一樣的,所以學(xué)會(huì)element-plus,其他類似于ant-design-vue、NaiveUI、VantUI都是差不多的;
  • 移動(dòng)端使用VantUI | MintUI
  • 安裝element-plus
npm install element-plus
1. 全局引入

一種引入element-plus的方式是全局引入,代表的含義是所有的組件和插件都會(huì)被自動(dòng)注冊(cè):

//main.ts
import { createApp } from 'vue';
import App from './App.vue';
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import router from './router'
import store from './store'

createApp(App).use(router).use(store).use(ElementPlus).mount('#app')
2. 局部引入(按需引入)

也就是在開發(fā)中用到某個(gè)組件對(duì)某個(gè)組件進(jìn)行引入:

2.1 手動(dòng)引入
<template>
    <div id="app">
      <el-row class="mb-4">
        <el-button disabled>Default</el-button>
        <el-button type="primary" disabled>Primary</el-button>
        <el-button type="success" disabled>Success</el-button>
        <el-button type="info" disabled>Info</el-button>
        <el-button type="warning" disabled>Warning</el-button>
        <el-button type="danger" disabled>Danger</el-button>
      </el-row>
    </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import { ElButton } from 'element-plus'

export default defineComponent({
  name: 'App',
  components: {
    ElButton
  }
})
</script>

<style lang="less">
</style>

但是我們會(huì)發(fā)現(xiàn)是沒(méi)有對(duì)應(yīng)的樣式的,引入樣式有兩種方式:

  • 全局引用樣式;import 'element-plus/dist/index.css'
  • 局部引用樣式(通過(guò) unplugin-element-plus 插件);

1.安裝插件:

npm install  unplugin-element-plus  -D

2.配置vue.config.js

const ElementPlus= require('unplugin-element-plus/webpack');
module.exports = {
  configureWebpack: {
    resolve: {
      alias: {
        components: '@/components'
      }
    },
    //配置webpack自動(dòng)按需引入element-plus樣式,
    plugins: [ElementPlus()]
  }
};

但是這里依然有個(gè)弊端:文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-491196.html

  • 這些組件我們?cè)诙鄠€(gè)頁(yè)面或者組件中使用的時(shí)候,都需要導(dǎo)入并且在components中進(jìn)行注冊(cè);
  • 所以我們可以將它們?cè)?strong>全局注冊(cè)一次;
import {
  ElButton,
  ElTable,
  ElAlert,
  ElAside,
  ElAutocomplete,
  ElAvatar,
  ElBacktop,
  ElBadge,
} from 'element-plus'

const app = createApp(App)

const components = [
  ElButton,
  ElTable,
  ElAlert,
  ElAside,
  ElAutocomplete,
  ElAvatar,
  ElBacktop,
  ElBadge
]

for (const cpn of components) {
  app.component(cpn.name, cpn)
}
2.3 自動(dòng)導(dǎo)入組件以及樣式[推薦】
1.安裝插件:
npm install -D unplugin-vue-components unplugin-auto-import
2.配置vue.config.js(其他配置方式看官網(wǎng))
const AutoImport = require('unplugin-auto-import/webpack');
const Components = require('unplugin-vue-components/webpack');
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers');
module.exports = {
  configureWebpack: {
    resolve: {
      alias: {
        components: '@/components'
      }
    },
    //配置webpack自動(dòng)按需引入element-plus,
    plugins: [
      AutoImport({
        resolvers: [ElementPlusResolver()]
      }),
      Components({
        resolvers: [ElementPlusResolver()]
      })
    ]
  }
};

3 直接使用
<template>
    <div id="app">
      <el-row class="mb-4">
        <el-button disabled>Default</el-button>
        <el-button type="primary" disabled>Primary</el-button>
        <el-button type="success" disabled>Success</el-button>
        <el-button type="info" disabled>Info</el-button>
        <el-button type="warning" disabled>Warning</el-button>
        <el-button type="danger" disabled>Danger</el-button>
      </el-row>
    </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue'

export default defineComponent({
})
</script>

<style lang="less">
</style>

到了這里,關(guān)于vue3 集成 Element-Plus之全局導(dǎo)入/按需導(dǎo)入的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

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

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

相關(guān)文章

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

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

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

    2024年02月06日
    瀏覽(107)
  • Vue3+TS+Vite創(chuàng)建項(xiàng)目,并導(dǎo)入Element-plus和Sass

    Vue3+TS+Vite創(chuàng)建項(xiàng)目,并導(dǎo)入Element-plus和Sass

    1.桌面新建一個(gè)文件夾Vue3-app 打開編輯器導(dǎo)入文件夾,編輯器打開終端輸入或者命令行工具cd到項(xiàng)目目錄下輸入 npm init vue@latest 回車運(yùn)行 這里我選擇了TS+Vite來(lái)開發(fā),并選擇安裝路由 2.cd到 vue-project目錄下 輸入 npm install 回車運(yùn)行 3.安裝完成后 輸入 npm run dev 回車運(yùn)行 瀏覽器打開

    2024年02月16日
    瀏覽(24)
  • 從零開始創(chuàng)建一個(gè)vue3+vite項(xiàng)目并集成element-plus、eslint以及prettier

    從零開始創(chuàng)建一個(gè)vue3+vite項(xiàng)目并集成element-plus、eslint以及prettier

    項(xiàng)目git地址, 歡迎修改提交,不足地方還請(qǐng)補(bǔ)充批評(píng)指正! 項(xiàng)目git地址 ESLint 是一個(gè)用于識(shí)別和報(bào)告在 ECMAScript/JavaScript 代碼中發(fā)現(xiàn)的模式的工具,其目標(biāo)是使代碼更加一致并避免錯(cuò)誤。 ESLint 是完全插件化的。每條規(guī)則都是一個(gè)插件,你可以在運(yùn)行時(shí)添加更多。你還可以添

    2024年04月09日
    瀏覽(27)
  • vue3使用element-plus

    vue3使用element-plus

    element-ui 是配合 vue2 使用,element-plus 是配置 vue3 使用的 1. 包管理器的方式 如果是使用?webpack 或者 vite 打包工具新建的項(xiàng)目 2. 瀏覽器直接導(dǎo)入 直接通過(guò)瀏覽器的 HTML 標(biāo)簽導(dǎo)入 Element Plus,然后就可以使用全局變量 ElementPlus 1. 導(dǎo)入全部組件且注冊(cè)所有的圖標(biāo) 聲明使用 ElementPl

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

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

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

    2024年02月15日
    瀏覽(28)
  • Vue3 封裝 element-plus 圖標(biāo)選擇器

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

    效果一: 效果二: ? 效果一的這個(gè)是把全部的icon圖標(biāo)都讓它顯示出來(lái),讓我們自己選擇說(shuō)選圖標(biāo) 2.1. 全局注冊(cè) icon 組件 2.2. 組件實(shí)現(xiàn)? 2.3. 使用? 效果二的這個(gè)是渲染后端返回的icon圖標(biāo) 3.1. 全局注冊(cè) icon 組件 3.2. 組件實(shí)現(xiàn)? 3.3. 使用?

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

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

    vue3+ts+element-plus上傳文件,預(yù)覽文件 場(chǎng)景:使用element-plus的el-upload標(biāo)簽,手動(dòng)上傳文件,可預(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)
  • vue3項(xiàng)目搭建并配置element-plus

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

    2024年02月13日
    瀏覽(30)
  • Webpack項(xiàng)目學(xué)習(xí):Vue-cli(腳手架)-優(yōu)化配置 -ui庫(kù)element-plus+減小打包體積 -按需加載+自定義主題+優(yōu)化

    Webpack項(xiàng)目學(xué)習(xí):Vue-cli(腳手架)-優(yōu)化配置 -ui庫(kù)element-plus+減小打包體積 -按需加載+自定義主題+優(yōu)化

    安裝 全部引入,在入口文件main.js ?啟動(dòng):npm start ?按需引入 需要插件快速開始 | Element Plus (gitee.io) ? ? 更改默認(rèn)配置 主題 | Element Plus (gitee.io) ? ?如果有模塊沒(méi)有安裝 ,安裝一下即可 優(yōu)化 關(guān)閉性能分析 文件單獨(dú)打包 做緩存-

    2024年02月08日
    瀏覽(99)
  • Vue3+element-plus實(shí)現(xiàn)后臺(tái)管理系統(tǒng)

    Vue3+element-plus實(shí)現(xiàn)后臺(tái)管理系統(tǒng)

    ?環(huán)境:node.js軟件 、Vs code、vite、elemnt-plus、windicss(樣式框架) ? ? 1、首先,使用npm 命令構(gòu)建項(xiàng)目( vscode安裝的插件 vscode中文顯示插件 ? 2、高亮提示插件volar ? 3、vue 3 sni 代碼提示) 快速上手 | Vue.js ? ?a. npm -v 查看node.js 版本 ? ?b. ?npm ?config get registry ? 查看注冊(cè)鏡像是

    2024年02月09日
    瀏覽(33)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包