一区二区日本_久久久久久久国产精品_无码国模国产在线观看_久久99深爱久久99精品_亚洲一区二区三区四区五区午夜_日本在线观看一区二区

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

目錄 element-plus集成 1. 全局引入 2. 局部引入(按需引入) 2.1 手動(dòng)引入 1.安裝插件: 2.配置vue.config.js 2.3 自動(dòng)導(dǎo)入組件以及樣式[推薦】 1.安裝插件: 2.配置vue.config.js(其他配置方式看官
目錄
  • element-plus集成
  • 1. 全局引入
  • 2. 局部引入(按需引入)
    • 2.1 手動(dòng)引入
      • 1.安裝插件:
      • 2.配置vue.config.js
    • 2.3 自動(dòng)導(dǎo)入組件以及樣式[推薦】
      • 1.安裝插件:
      • 2.配置vue.config.js(其他配置方式看官網(wǎng))
      • 3 直接使用
  • 總結(jié)

    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)是沒有對(duì)應(yīng)的樣式的,引入樣式有兩種方式:

    全局引用樣式;import 'element-plus/dist/index.css'

    局部引用樣式(通過 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è)弊端:

    • 這些組件我們?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>

    總結(jié)

    到此這篇關(guān)于vue3集成Element-Plus之全局導(dǎo)入和按需導(dǎo)入的文章就介紹到這了,更多相關(guān)Element-Plus全局導(dǎo)入和按需導(dǎo)入內(nèi)容請(qǐng)搜索技圈網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持技圈網(wǎng)!

    聲明:所有內(nèi)容來(lái)自互聯(lián)網(wǎng)搜索結(jié)果,不保證100%準(zhǔn)確性,僅供參考。如若本站內(nèi)容侵犯了原著者的合法權(quán)益,可聯(lián)系我們進(jìn)行處理。
    發(fā)表評(píng)論
    更多 網(wǎng)友評(píng)論0 條評(píng)論)
    暫無(wú)評(píng)論

    返回頂部

    主站蜘蛛池模板: 亚洲精品一区二区三区蜜桃久 | 婷婷国产一区 | 日日摸日日碰夜夜爽亚洲精品蜜乳 | 国产成人精品久久 | 国产东北一级毛片 | 日皮视频免费 | 国产91在线 | 亚洲 | 免费一区在线 | 岛国毛片在线观看 | 福利社午夜影院 | 国产97视频在线观看 | 精品国产精品三级精品av网址 | 日韩精品一区二区三区视频播放 | 亚洲一区二区三区免费在线 | 欧美高清视频在线观看 | 2018国产精品 | 在线看中文字幕 | 日韩a视频| 成人精品在线视频 | 国产一区 日韩 | 一区二区三区不卡视频 | 狠狠躁躁夜夜躁波多野结依 | 中文字幕精品视频 | 免费一级大片 | 日本成人毛片 | 一区二区三区四区在线视频 | 亚州春色 | 精品一级电影 | 久久天堂 | 欧美日本韩国一区二区三区 | 夜夜爽99久久国产综合精品女不卡 | 日韩专区中文字幕 | 91日日| 日韩午夜| 黄色一级视频免费 | 欧美三级网站 | 亚洲精品久久久久久久久久久 | 国产精品久久久久久久岛一牛影视 | 日韩久久在线 | 久久久久国 | 欧美在线视频观看 |