一个简易版的组件库二次封装

参考链接:本文基于此进行修改

vue3 对ant-design-vue 按钮组件进行二次封装_a-button二次封装-CSDN博客

组件库依赖:ant-design-vue

用ant-design-vue开发可以参考:Ant design + Vue_vue antdv4, 按需引入-CSDN博客

主要修改以下两个文件

1.index.vue

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

<script setup lang="ts">
import { defineProps, defineEmits } from 'vue'
import { PlusOutlined, EditTwoTone } from '@ant-design/icons-vue'

const props = defineProps({
  text: {
    type: String,
    default: '编辑'
  },
  type: {
    type: String,
    default: 'edit'
  },
  isAble: {
    type: Boolean,
    default: false
  }
})

const emits = defineEmits(['click'])

const handleClick = () => {
  emits('click')
}
</script>

<style lang="scss" scoped>
/* 样式可以根据需要添加 */
</style>

2.App.vue

<script setup lang="ts">
// import HelloWorld from './components/HelloWorld.vue'
import LButton from 'D:/projects/lanyn_ui/packages/button/src/index.vue'

</script>

<template>
  <!-- <HelloWorld msg="Vite + Vue" /> -->
  <LButton type="edit" text="test1"></LButton>
  <LButton type="add" text="test2"></LButton>
</template>

<style scoped>

</style>

3.效果展示

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值