亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

vue3集成Element-Plus之全局導入和按需導入

瀏覽:3日期:2022-06-13 10:06:27
目錄element-plus集成1. 全局引入2. 局部引入(按需引入)2.1 手動引入1.安裝插件:2.配置vue.config.js2.3 自動導入組件以及樣式[推薦】1.安裝插件:2.配置vue.config.js(其他配置方式看官網)3 直接使用總結element-plus集成

Element Plus,一套為開發者、設計師和產品經理準備的基于 Vue 3.0 的桌面端組件庫:

在Vue2中使用element-ui,而element-plus是element-ui針對于vue3開發的一個UI組件庫;它的使用方式和很多其他的組件庫是一樣的,所以學會element-plus,其他類似于ant-design-vue、NaiveUI、VantUI都是差不多的;移動端使用VantUI | MintUI安裝element-plusnpm install element-plus1. 全局引入

一種引入element-plus的方式是全局引入,代表的含義是所有的組件和插件都會被自動注冊:

//main.tsimport { 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. 局部引入(按需引入)

也就是在開發中用到某個組件對某個組件進行引入:

2.1 手動引入<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>

但是我們會發現是沒有對應的樣式的,引入樣式有兩種方式:

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

局部引用樣式(通過 unplugin-element-plus 插件);

1.安裝插件:npm install unplugin-element-plus -D2.配置vue.config.jsconst ElementPlus= require('unplugin-element-plus/webpack');module.exports = { configureWebpack: { resolve: { alias: {components: '@/components' } }, //配置webpack自動按需引入element-plus樣式, plugins: [ElementPlus()] }};

但是這里依然有個弊端:

這些組件我們在多個頁面或者組件中使用的時候,都需要導入并且在components中進行注冊;所以我們可以將它們在全局注冊一次;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 自動導入組件以及樣式[推薦】1.安裝插件:npm install -D unplugin-vue-components unplugin-auto-import2.配置vue.config.js(其他配置方式看官網)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自動按需引入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>總結

到此這篇關于vue3集成Element-Plus之全局導入和按需導入的文章就介紹到這了,更多相關Element-Plus全局導入和按需導入內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: JavaScript
主站蜘蛛池模板: 午夜一区二区三区 | 黄色片网站大全 | 国产伦精品一区三区视频 | 亚洲电影一区二区三区 | 真人肉体一级毛片 | 欧美亚洲国产精品久久蜜芽 | 91在线视频在线 | 丁香婷婷亚洲六月综合色 | 国产精品99久久久久久人 | 亚洲欧美色图 | 欧美人妖猛交 | 99视频在线精品 | 九九视频免费在线 | 日韩免费毛片 | 九九精品视频在线 | 91高清视频 | 91香蕉视频苹果 | 欧美日韩国产一区二区 | 欧美精品午夜 | 伊人中文字幕 | 精品视频99| 伊人色婷婷综在合线亚洲 | 成年女人毛片免费视频 | 黄色在线免费看 | 亚洲色图国产精品 | 国产视频xxxx | 美女巨胸喷奶水gif放肆吧 | 自拍 第一页 | 一级毛片一级毛片a毛片欧美 | 国产成人精视频在线观看免费 | 无遮挡高清一级毛片免费 | 精品一区二区视频 | 999www成人免费视频 | 国产乱小说 | 亚洲绝美精品一区二区 | 国产精品国产精品 | 欧美精品一区二区三区在线播放 | 国产乱子精品免费视观看片 | 中日韩精品视频在线观看 | 草妞视频 | 国产激情一区二区三区 |