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>
相关推荐
遇到困难睡大觉哈哈2 小时前
Harmony os 静态卡片(ArkTS + FormLink)详细介绍
前端·microsoft·harmonyos·鸿蒙
用户47949283569152 小时前
Bun 卖身 Anthropic!尤雨溪神吐槽:OpenAI 你需要工具链吗?
前端·openai·bun
p***43482 小时前
前端在移动端中的网络请求优化
前端
g***B7382 小时前
前端在移动端中的Ionic
前端
大猩猩X3 小时前
vxe-gantt 甘特图使用右键菜单
vue.js·vxe-table·vxe-ui·vxe-gantt
拿破轮3 小时前
使用通义灵码解决复杂正则表达式替换字符串的问题.
java·服务器·前端
whltaoin3 小时前
【 Web认证 】Cookie、Session 与 JWT Token:Web 认证机制的原理、实现与对比
前端·web·jwt·cookie·session·认证机制
Aerelin3 小时前
爬虫playwright入门讲解
前端·javascript·html·playwright
笙年3 小时前
JavaScript Promise,包括构造函数、对象方法和类方法
开发语言·javascript·ecmascript
桜吹雪3 小时前
LangChain.js/DeepAgents可观测性
javascript·人工智能