Skip to content

Button 按钮

基本使用

html
<be-button class="button-1" hover>按钮</be-button>
scss
.button-1 {
  width: 80px;
  height: 30px;
  border-radius: 8px;
  background-color: #4a68cc;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 12px;
  color: #ffffff;
}

不同状态按钮

html
<be-button class="button-1" :loading="loading" :disabled="disabled" disabled-class="disabled">
  {{ statusText }}
  <template #loading>
    <image class="loading-icon" src="/static/xxx/loading.png" mode="scaleToFill" />
  </template>
</be-button>
<be-button class="button-2" hover @click="switchStatus">切换状态</be-button>
ts
import { ref, computed } from 'vue';

const loading = ref(false);
const disabled = ref(false);
const status = ref('normal');

const statusText = computed(() => {
  return status.value === 'normal' ? '按钮' : status.value === 'loading' ? '加载中' : '不可用';
});

const switchStatus = () => {
  if (status.value === 'normal') {
    loading.value = true;
    status.value = 'loading';
  } else if (status.value === 'loading') {
    loading.value = false;
    disabled.value = true;
    status.value = 'disabled';
  } else {
    disabled.value = false;
    status.value = 'normal';
  }
};
scss
.button-1,
.button-2 {
  width: 80px;
  height: 30px;
  border-radius: 8px;
  background-color: #4a68cc;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 12px;
  color: #ffffff;
}

.button-1 {
  &:active {
    background-color: darken(#4a68cc, 20%);
  }

  &.disabled {
    background-color: #aaaaaa;
  }

  .loading-icon {
    width: 16px;
    height: 16px;
    animation: uni-loading 1s linear infinite;
    margin-right: 6rpx;
  }
}

.button-2 {
  margin-left: 10px;
}

API

Props

属性名说明类型默认值
rootClass根节点 classstring-
rootStyle根节点 stylestring-
hover默认点击效果booleanfalse
hoverClass自定义点击样式string-
loading按钮加载状态(加载时会添加 data-loading 属性,可用于样式控制)booleanfalse
hiddenContentInLoading加载时隐藏按钮内容booleanfalse
loadingIcon自定义加载图标Icon Props{ fontFamily?: 'iconfont', prefix?: 'icon-', name: '' }
loadingSize自定义加载图标大小css font-sizeunset
loadingColor自定义加载图标颜色css colorunset
disabled按钮禁用状态booleanfalse
disabledClass自定义禁用样式string-

Props extend uni-app button

属性名说明默认值
openType属性说明-
sessionFrom属性说明-

Events extend uni-app button

事件名称说明
getphonenumber事件说明
getuserinfo事件说明
error事件说明
click事件说明

Slots

插槽名说明slot props默认值
loading自定义加载样式-
default按钮内容-