element-plus怎么实现按需导入,具体操作是什么
Admin 2022-07-13 群英技术资讯 1491 次浏览
这篇文章给大家分享的是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进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
本文主要介绍了vue/react单页应用后退不刷新方案,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
utf8编码算法是什么样的,如何实现?小编这就来给大家分析分析下,对此感兴趣的话可以看看以下知识点,有需要的朋友一定不要错过了。
这篇文章主要给大家介绍了关于微信小程序获取手机号踩坑的相关资料,详细记录了踩坑的过程以及解决的方法和猜想,通过示例代码以及图片介绍的非常详细,需要的朋友可以参考下
jquery判断当前元素是第几个的方法:1、创建一个HTML示例文件;2、通过jQuery代码“$("ul li").click(function () {var index = $("ul li").index...})”进行判断即可。
JS实现懒加载图片方法有哪些?实现懒加载图片方法有很多,这篇文章就给大家分享三种利用原生JS实现懒加载lazyLoad的方法以及对比,下文实例对大家理解JS实现懒加载图片有一定的帮助,下面我们一起来看看吧。
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
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备09006778号 域名注册商资质 粤 D3.1-20240008