当前位置: 首页 > news >正文

【Vue3】3-6 : 仿ElementPlus框架的el-button按钮组件实

文章目录

    • 前言
  • 本节内容
    • 实现需求
    • 完整代码如下:

前言

上节,我们学习了

  • slot插槽,组件内容的分发处理

本节内容

本小节利用前面学习的组件通信知识,来完成一个仿Element Plus框架的el-button按钮组件实现
仿造的地址:uhttps://element-plus.org/zh-CN/component/button.html

实现需求

  • 按钮类型
  • 按钮尺寸
  • 按钮文字
  • 添加图标

完整代码如下:

<style>.el-button{display: inline-flex;justify-content: center;align-items: center;line-height: 1;height: 32px;white-space: nowrap;cursor: pointer;background-color: #ffffff;border: 1px solid #dcdfe6;border-color: #dcdfe6;;color: #606266;-webkit-appearance: none;text-align: center;box-sizing: border-box;outline: none;transition: .1s;font-weight: 500;user-select: none;vertical-align: middle;padding: 8px 15px;font-size: 14px;border-radius: 4px;}.el-button--primary{color: white;background-color: #409eff; }.el-button--success{color: white;background-color: #67c23a; }.el-button--large{height: 40px;padding: 12px 19px;font-size: 14px;}.el-button--small{height: 24px;padding: 5px 11px;font-size: 12px;border-radius: 3px;}
</style>
<link rel="stylesheet" href="./iconfont/iconfont.css">
<script src="../vue.global.js"></script>
<div id="app"><el-button>default</el-button><el-button type="primary" size="small">Primary</el-button><el-button type="success" size="large">Success</el-button><el-button type="success" size="large"><template #icon><i class="iconfont iconfangdajing"></i></template>Success</el-button></div>
<script>let ElButton = {data(){return {buttonClass: {'el-button': true,[`el-button--${this.type}`]: this.type !== '', [`el-button--${this.size}`]: this.size !== '' }}},props: {type: {type: String,default: ''},size: {type: String,default: ''}},template: `<button :class="buttonClass"><slot name="icon"></slot><slot></slot></button>`};let vm = Vue.createApp({data(){return {}},components: {ElButton}}).mount('#app');
</script>

在这里插入图片描述

http://www.lryc.cn/news/311174.html

相关文章:

  • .datastore@cyberfear.com.mkp勒索病毒的最新威胁:如何恢复您的数据?
  • 23.基于springboot + vue实现的前后端分离-在线旅游网站系统(项目 + 论文PPT)
  • SpringCloud-RabbitMQ消息模型
  • Linux网络编程 ——UDP 通信
  • TDengine 签约树根互联,应对“高基数”难题
  • 实名制交友-智能匹配-仿二狗交友系统-TP6+uni-APP小程序H5公众号-源码交付-支持二开!
  • 在CentOS上使用Gunicorn和systemd完整部署Flask应用:详细指南
  • 【信息系统项目管理师】--【信息技术发展】--【新一代信息技术及应用】--【人工智能】
  • 注意力机制(代码实现案例)
  • 全量知识系统问题及SmartChat给出的答复 之8 三套工具之3语法解析器 之1
  • 软考59-上午题-【数据库】-小结+杂题
  • 【ARM Trace32(劳特巴赫) 高级篇 21 -- SystemTrace ITM 使用介绍】
  • Python系列(20)—— 循环语句
  • MYSQL的sql性能优化技巧
  • C#(C Sharp)学习笔记_数组的遍历【十】
  • 掌握未来技术:一站式深度学习学习平台体验!
  • Doris实战——特步集团零售数据仓库项目实践
  • 【python】(4)条件和循环
  • Docker 的基本概念
  • 5.44 BCC工具之killsnoop.py解读
  • 2023人机交互期末复习
  • Linux使用bcache 将SSD加速硬盘
  • 大厂报价查询系统性能优化之道!
  • Carbondata编译适配Spark3
  • 数学建模【灰色关联分析】
  • Vue.js的单向数据流:让你的应用更清晰、更可控
  • IntelliJ IDEA社区版传统web开发环境搭建
  • arm-linux-gnueabi、arm-linux-gnueabihf 交叉编译器区别
  • 什么是RS485
  • 2024.3.4