vue 基于element-plus el-button封装按钮组件

封装组件的原则是:组件只是数据流通的一个管道,不要糅合太多的逻辑在里面,是一个纯组件,还要根据自己项目的业务场景做具体的处理。

javascript 复制代码
// MyButton.vue
// 基于element-plus中el-button来封装按钮
<template>
    <el-button @click="handleClick">
        <div class="btn-text-style"> // 文本样式
            <slot></slot> // 预留按钮文本插槽
        </div>
    </el-button>
</template>

<script setup>
const emits = defineEmits(['click'])
// 出发click事件
const handleClick = () => {
    emits('click')
}

</script>

<style>
.btn-text-style {
    font-size: 14px;
    font-weight: bold;
    font-family: 'Courier New', Courier, monospace;
}
</style>
javascript 复制代码
// 在具体组件中的使用
// 根据透传Attributes 即属性的继承
// 透传 attribute 指的是传递给一个组件,却没有被该组件声明为 props 或 emits 的 attribute
// 或者 v-on 事件监听器。最常见的例子就是 class、style 和 id。
// 我们在父组件中添加的各种属性都会被子组件继承下来,所以有了 type, size, icon等这些属性
<template #footer>
    <span class="dialog-footer">
        <MyButton @click="cancel" type="info" size="mini" disabeld icon="Edit">取消</MyButton>
        <MyButton type="primary" @click="submitForm">确定</MyButton>
    </span>
</template>
相关推荐
小飞侠在吗20 小时前
vue props
前端·javascript·vue.js
DsirNg21 小时前
页面栈溢出问题修复总结
前端·微信小程序
小徐_233321 小时前
uni-app 也能远程调试?使用 PageSpy 打开调试的新大门!
前端·微信小程序·uni-app
大怪v1 天前
【Virtual World 03】上帝之手
前端·javascript
用户841794814561 天前
vxe-gantt 甘特图实现产品进度列表,自定义任务条样式和提示信息
vue.js
招来红月1 天前
记录JS 实用API
javascript
别叫我->学废了->lol在线等1 天前
演示 hasattr 和 ** 解包操作符
开发语言·前端·python
霍夫曼1 天前
UTC时间与本地时间转换问题
java·linux·服务器·前端·javascript
VX:Fegn08951 天前
计算机毕业设计|基于Java人力资源管理系统(源码+数据库+文档)
java·开发语言·数据库·vue.js·spring boot·后端·课程设计
DARLING Zero two♡1 天前
浏览器里跑 AI 语音转写?Whisper Web + cpolar让本地服务跑遍全网
前端·人工智能·whisper