利用vant组件封装button

5 篇文章 1 订阅
<template>
  <van-button
    class="i-button"
    type="default"
    round
    :class="classMap"
    :icon="icon"
    :size="size"
    :loading="loading"
    :loading-text="loadingText"
    :loading-type="loadingType"
    :loading-size="loadingSize"
    :disabled="disabled"
    @click="$emit('click', $event)"
    @touchstart="$emit('touchstart', $event)"
  >
    <slot />
  </van-button>
</template>
<script>
// 这里只提供了 van-button 部分功能, 其他功能需要使用时自行添加
// 参开文档  https://vant-contrib.gitee.io/vant/#/zh-CN/button
export default {
  props: {
    // default|primary|gradient|grey
    type: {
      type: String,
      default: 'default'
    },
    // 图标
    icon: {
      type: String,
      default: ''
    },
    // 是否显示为加载状态
    loading: {
      type: Boolean,
      default: false
    },
    // 加载状态提示文字
    loadingText: {
      type: String,
      default: ''
    },
    // 加载图标类型,可选值为 spinner
    loadingType: {
      type: String,
      default: 'circular'
    },
    // 加载图标大小
    loadingSize: {
      type: String,
      default: '20px'
    },
    // 是否禁用按钮
    disabled: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    classMap() {
      return {
        primary: this.type === 'primary',
        grey: this.type === 'grey',
        gradient: this.type === 'gradient'
      };
    },
    size() {
      return this.type === 'gradient' ? 'large' : 'small';
    }
  }
};
</script>
<style lang="less" scoped>
.i-button {
  font-size: 13px;
  color: #262626;
  border-color: #d9d9d9;
  padding: 4px 10px;
  background-color: #fff;

  .van-icon {
    font-size: 13px;
  }
  &:not(.gradient) {
    height: 26px;
    line-height: 26px;
  }
}
.primary {
  color: @red;
  background-color: @red-bg;
  border-color: @red-bg;
}

.grey {
  border-color: #f4f5f7;
  background-color: #f4f5f7;
}
.gradient {
  background: linear-gradient(to right, #e92f60, #f9792a);
  border: 1px solid transparent;
  border-radius: 10px;
  color: #fff;
  font-size: 16px;
}
</style>

使用

  <i-button type="primary">切换</i-button>
    <i-button type="default">查看详情</i-button>
    <i-button type="grey" icon="plus">新增报修</i-button>
    <i-button type="gradient">渐变</i-button>

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值