vue3 对ant-design-vue 按钮组件进行二次封装

我们要实现的需求,在表格action栏,按钮以图标形式展示,移动到图标上有对应的按钮操作提示。
因为页面复用的比较多,所以对图标根据业务需求进行了二次封装

组件代码结构如下

在这里插入图片描述
index的内容:

<template>
  <!-- 新增 -->
  <template v-if="type==='add'">
    <a-tooltip :title="text" color="#87d068">
      <a-button shape="circle" @click="handleClick">
        <template #icon>
          <PlusOutlined/>
        </template>
      </a-button>
    </a-tooltip>
  </template>
  <!-- 编辑 -->
  <template v-if="type==='edit'">
    <a-tooltip :title="text" color="#87d068">
      <a-button shape="circle" :disabled="isAble" @click="handleClick">
        <template #icon>
          <EditTwoTone />
        </template>
      </a-button>
    </a-tooltip>
  </template>
</template>

<script lang="ts">
import { defineComponent } from 'vue'

export default defineComponent({
  name: 'index',
  // props简单语法
  // props: ['text'],
  emits: ['click'],
  // text 按钮操作提示的文本,type 按钮类型,isAble 按钮是否可用
  props: {
    text: {
      type: String,
      default: '编辑'
    },
    type: {
      type: String,
      default: 'edit'
    },
    isAble: {
      type: Boolean,
      default: false
    }
  },
  setup (prop, ctx) {
   // 对外抛出click事件
    const methods = {
      handleClick () {
        ctx.emit('click')
      }
    }
    return {
      ...methods
    }
  }
})
</script>
<style lang="scss" scoped>
</style>

页面使用

在页面对我们封装的组件进行引入,也可以使用全局引用的方式,参考vue3全局注册组件
在这里插入图片描述

效果展示

在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值