vue 所有按钮属性、vue Button 所有按钮属性事件、vue a-button 所有按钮属性事件、vue 按钮所有属性事件、vue

vue 所有按钮属性、vue Button 所有按钮属性事件、vue a-button 所有按钮属性事件、vue 按钮所有属性事件、vue

  • 1.组件注册
    • 1.按钮类型
    • 2.按钮组合
    • 3.不可用状态
    • 4.幽灵按钮
    • 5.图标按钮
    • 6.加载中状态
    • 7.多个按钮组合
    • 8.按钮尺寸
    • 9.block 按钮
  • 2.API
    • 1.属性:
    • 2.事件

1.组件注册

import { Button } from ‘ant-design-vue’;
Vue.use(Button);

1.按钮类型

vue 所有按钮属性、vue Button 所有按钮属性事件、vue a-button 所有按钮属性事件、vue 按钮所有属性事件、vue_第1张图片
按钮有四种类型:主按钮、次按钮、虚线按钮、危险按钮和链接按钮。主按钮在同一个操作区域最多出现一次。

<template>
  <div>
    <a-button type="primary">Primarya-button>
    <a-button>Defaulta-button>
    <a-button type="dashed">Dasheda-button>
    <a-button type="danger">Dangera-button>
    <a-button type="link">Linka-button>
  div>
template>

2.按钮组合

vue 所有按钮属性、vue Button 所有按钮属性事件、vue a-button 所有按钮属性事件、vue 按钮所有属性事件、vue_第2张图片
可以将多个 Button 放入 Button.Group 的容器中。
通过设置 sizelarge small 分别把按钮组合设为大、小尺寸。若不设置 size,则尺寸为中。

<template>
  <div id="components-button-demo-button-group">
    <h4>Basich4>
    <a-button-group>
      <a-button>Cancela-button>
      <a-button type="primary">OKa-button>
    a-button-group>
    <a-button-group>
      <a-button disabled>La-button>
      <a-button disabled>Ma-button>
      <a-button disabled>Ra-button>
    a-button-group>
    <a-button-group>
      <a-button type="primary">La-button>
      <a-button>Ma-button>
      <a-button>Ma-button>
      <a-button type="dashed">Ra-button>
    a-button-group>

    <h4>With Iconh4>
    <a-button-group>
      <a-button type="primary">
        <a-icon type="left" />Go back
      a-button>
      <a-button type="primary">
        Go forward<a-icon type="right" />
      a-button>
    a-button-group>
    <a-button-group>
      <a-button type="primary" icon="cloud" />
      <a-button type="primary" icon="cloud-download" />
    a-button-group>
  div>
template>
<style>
#components-button-demo-button-group h4 {
  margin: 16px 0;
  font-size: 14px;
  line-height: 1;
  font-weight: normal;
}
#components-button-demo-button-group h4:first-child {
  margin-top: 0;
}
#components-button-demo-button-group .ant-btn-group {
  margin-right: 8px;
}
style>

3.不可用状态

vue 所有按钮属性、vue Button 所有按钮属性事件、vue a-button 所有按钮属性事件、vue 按钮所有属性事件、vue_第3张图片
添加 disabled 属性即可让按钮处于不可用状态,同时按钮样式也会改变

<template>
  <div>
    <a-button type="primary">Primarya-button>
    <a-button type="primary" disabled>Primary(disabled)a-button>
    <br />
    <a-button>Defaulta-button>
    <a-button disabled>Default(disabled)a-button>
    <br />
    <a-button type="dashed">Dasheda-button>
    <a-button type="dashed" disabled>Dashed(disabled)a-button>
    <br />
    <a-button type="link">Linka-button>
    <a-button type="link" disabled>Link(disabled)a-button>
    <div :style="{ padding: '8px 8px 0 8px', background: 'rgb(190, 200, 200)' }">
      <a-button ghost>Ghosta-button>
      <a-button ghost disabled>Ghost(disabled)a-button>
    div>
  div>
template>

4.幽灵按钮

vue 所有按钮属性、vue Button 所有按钮属性事件、vue a-button 所有按钮属性事件、vue 按钮所有属性事件、vue_第4张图片
幽灵按钮将其他按钮的内容反色,背景变为透明,常用在有色背景上。

<template>
  <div :style="{ background: 'rgb(190, 200, 200)', padding: '26px 16px 16px' }">
    <a-button type="primary" ghost>Primarya-button>
    <a-button ghost>Defaulta-button>
    <a-button type="dashed" ghost>Dasheda-button>
    <a-button type="danger" ghost>Dangera-button>
    <a-button type="link" ghost>Linka-button>
  div>
template>

5.图标按钮

vue 所有按钮属性、vue Button 所有按钮属性事件、vue a-button 所有按钮属性事件、vue 按钮所有属性事件、vue_第5张图片
当需要在 Button 内嵌入 Icon 时,可以设置 icon 属性,或者直接在 Button 内使用 Icon 组件。
如果想控制 Icon 具体的位置,只能直接使用 Icon 组件,而非 icon 属性。

<template>
  <div>
    <a-button type="primary" shape="circle" icon="search">a-button>
    <a-button type="primary" icon="search">Searcha-button>
    <a-button shape="circle" icon="search" />
    <a-button icon="search">Searcha-button>
    <a-button shape="circle" icon="search" />
    <a-button icon="search">Searcha-button>
    <a-button type="dashed" shape="circle" icon="search" />
    <a-button type="dashed" icon="search">Searcha-button>
  div>
template>

6.加载中状态

第三个按钮为悬浮:
vue 所有按钮属性、vue Button 所有按钮属性事件、vue a-button 所有按钮属性事件、vue 按钮所有属性事件、vue_第6张图片
添加 loading 属性即可让按钮处于加载状态,最后两个按钮演示点击后进入加载状态。

<template>
  <div>
    <a-button type="primary" loading>
      Loading
    a-button>
    <a-button type="primary" size="small" loading>
      Loading
    a-button>
    <br />
    <a-button type="primary" :loading="loading" @mouseenter="enterLoading">
      mouseenter me!
    a-button>
    <a-button type="primary" icon="poweroff" :loading="iconLoading" @click="enterIconLoading">
      延迟1s
    a-button>
    <br />
    <a-button shape="circle" loading />
    <a-button type="primary" shape="circle" loading />
  div>
template>
<script>
export default {
  data () {
    return {
      loading: false,
      iconLoading: false,
    }
  },
  methods: {
    enterLoading () {
      this.loading = true
    },
    enterIconLoading () {
      this.iconLoading = { delay: 1000 }
    },
  },
}
script>

7.多个按钮组合

vue 所有按钮属性、vue Button 所有按钮属性事件、vue a-button 所有按钮属性事件、vue 按钮所有属性事件、vue_第7张图片
按钮组合使用时,推荐使用1个主操作 + n 个次操作,3个以上操作时把更多操作放到 Dropdown.Button 中组合使用。

<template>
  <div>
    <a-button type="primary">Primarya-button>
    <a-button>secondarya-button>
    <a-dropdown>
      <a-menu slot="overlay" @click="handleMenuClick">
        <a-menu-item key="1">1st itema-menu-item>
        <a-menu-item key="2">2nd itema-menu-item>
        <a-menu-item key="3">3rd itema-menu-item>
      a-menu>
      <a-button>
        Actions <a-icon type="down" />
      a-button>
    a-dropdown>
  div>
template>
<script>
export default {
  methods: {
    handleMenuClick(e) {
      console.log('click', e);
    }
  }
}
script>

8.按钮尺寸

vue 所有按钮属性、vue Button 所有按钮属性事件、vue a-button 所有按钮属性事件、vue 按钮所有属性事件、vue_第8张图片
按钮有大、中、小三种尺寸。
通过设置 sizelarge small 分别把按钮设为大、小尺寸。若不设置 size,则尺寸为中。

<template>
  <div>
    <a-radio-group :value="size" @change="handleSizeChange">
      <a-radio-button value="large">Largea-radio-button>
      <a-radio-button value="default">Defaulta-radio-button>
      <a-radio-button value="small">Smalla-radio-button>
    a-radio-group>
    <br /><br />
    <a-button type="primary" :size="size">Primarya-button>
    <a-button :size="size">Normala-button>
    <a-button type="dashed" :size="size">Dasheda-button>
    <a-button type="danger" :size="size">Dangera-button>
    <a-button type="link" :size="size">Linka-button>
    <br />
    <a-button type="primary" shape="circle" icon="download" :size="size" />
    <a-button type="primary" icon="download" :size="size">Downloada-button>
    <br />
    <a-button-group :size="size">
      <a-button type="primary">
        <a-icon type="left" />Backward
      a-button>
      <a-button type="primary">
        Forward<a-icon type="right" />
      a-button>
    a-button-group>
  div>
template>
<script>
export default {
  data () {
    return {
      size: 'large',
    }
  },
  methods: {
    handleSizeChange (e) {
      this.size = e.target.value
    },
  },
}
script>

9.block 按钮

vue 所有按钮属性、vue Button 所有按钮属性事件、vue a-button 所有按钮属性事件、vue 按钮所有属性事件、vue_第9张图片
block属性将使按钮适合其父宽度。

<template>
  <div>
    <a-button type="primary" block>Primarya-button>
    <a-button block>Defaulta-button>
    <a-button type="dashed" block>Dasheda-button>
    <a-button type="danger" block>Dangera-button>
    <a-button type="link" block>Linka-button>
  div>
template>

2.API

1.属性:

推荐顺序为:type -> shape -> size -> loading -> disabled

属性 说明 类型 默认值
disabled 按钮失效状态 boolean false
ghost 幽灵属性,使按钮背景透明,版本 2.7 中增加 boolean false
href 点击跳转的地址,指定此属性 button 的行为和 a 链接一致 string -
htmlType 设置 button 原生的 type 值,可选值请参考 HTML 标准 string button
icon 设置按钮的图标类型 string -
loading 设置按钮载入状态 boolean | { delay: number } false
shape 设置按钮形状,可选值为 circle round 或者不设 string -
size 设置按钮大小,可选值为 small large 或者不设 string default
target 相当于 a 链接的 target 属性,href 存在时生效 string -
type 设置按钮类型,可选值为 primary dashed danger link 或者不设 string -
block 将按钮宽度调整为其父宽度的选项 boolean false

2.事件

事件名称 说明 回调参数
click 点击按钮时的回调 (event) => void

你可能感兴趣的:(Ant,Design,of,Vue)