element-plus怎么实现按需导入,具体操作是什么
Admin 2022-07-13 群英技术资讯 1877 次浏览
这篇文章给大家分享的是element-plus怎么实现按需导入,具体操作是什么。小编觉得挺实用的,因此分享给大家做个参考,文中的介绍得很详细,而要易于理解和学习,有需要的朋友可以参考,接下来就跟随小编一起了解看看吧。安装插件
首先需要引入额外的插件:前**vite-plugin-components已重命名为unplugin-vue-components**
npm install unplugin-vue-components
配置插件
在weapack或vite配置文件内中添加配置
// vite.config.ts
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
export default {
plugins: [
// ...
Components({
resolvers: [ElementPlusResolver()],
}),
],
}
// webpack.config.js
const Components = require('unplugin-vue-components/webpack')
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')
module.exports = {
// ...
plugins: [
Components({
resolvers: [ElementPlusResolver()],
}),
],
}
//main.ts
import { createApp } from 'vue'
import App from './App.vue'
import { Edit,Search } from '@element-plus/icons' //图标需要分开导入,按需导入图标
import { ElButton } from 'element-plus'; //按需导入
const app = createApp(App);
//注册组件
app.component("edit", Edit)
app.component("search", Search)
app.component('ElButton',ElButton)
app.mount('#app');
<template>
<h2>home页面</h2>
<el-button type="primary" >主要按钮</el-button>
<el-button type="success" >成功按钮</el-button>
<el-icon :size="20" :color="'blue'">
<edit />
</el-icon>
<el-icon :size="20">
<search></search>
</el-icon>
</template>
<script setup lang="ts">
</script>
推荐添加
// tsconfig.json
{
"compilerOptions": {
// ...
"types": ["element-plus/global"]
}
}
安装
npm install element-plus --save # or yarn add element-plus # 安装icon图标依赖库 npm install @element-plus/icons # or yarn add @element-plus/icons
在main.ts 文件中全局配置
import { createApp } from 'vue'
import App from './App.vue'
import { store, key } from './store';
// 注入路由
import router from './router';
// 全局引入ui库
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
const app = createApp(App);
app.use(store, key);
app.use(router);
app.use(ElementPlus);
app.mount('#app');
使用ui组件
使用图标,因为图标和普通ui组件不是同一个包,使用需要分别导入
//导入具体的组件后直接使用
<template>
<el-icon :size="20" :color="'blue'">
<edit />
</el-icon>
</template>
<script setup lang="ts">
import { Edit } from '@element-plus/icons'
</script>
将图标库在main.ts文件中impott并使用app.component()注册便可以直接在组件中使用了,和普通的使用ui库同理
<template>
<h2>home页面</h2>
<el-button type="primary" >主要按钮</el-button>
<el-button type="success" >成功按钮</el-button>
<el-icon :size="20" :color="'blue'">
<edit />
</el-icon>
<el-icon :size="20">
<search></search>
</el-icon>
</template>
<script setup lang="ts">
</script>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
今天给大家分享的是关于JavaScript中分号的内容,一些朋友会纠结加不加分号的问题,其实掌握分好的作用,这个问题就很好解决了。对此,下面小编就给大家介绍一下JavaScript中分号的作用及要注意的几点。
本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了事件循环的相关内容,下面一起来看一下,希望对大家有帮助。
本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于数组去重的相关问题,包括了es6的set去重、双重for循环去重、indexof去重等等内容,下面一起来看一下,希望对大家有帮助。
这篇文章主要介绍了antdesign-vue结合sortablejs实现两个table相互拖拽排序功能,本文通过实例图文相结合给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
js怎样实现浏览器储存功能?有什么方法?对于浏览器的存储方案,我们比较常见的有Cookie、LocalStorage等,下面我们就来看看它们有何不同?
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 ICP核准(ICP备案)粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008