VEUI

VEUI on GitHub
Play!中文

Checkbox

Examples

Size variants

Available ui prop values: s / m.

Use the indeterminate prop to put the checkbox in indeterminate state.

Edit this demo on GitHubEdit
<template>
<article>
  <section>
    <veui-checkbox
      v-model="checked"
      class="checkbox"
      :ui="size"
      :indeterminate.sync="indeterminate"
    >
      Checked: {{ checked }}
    </veui-checkbox>
  </section>
  <section>
    <veui-checkbox
      v-model="small"
      class="checkbox"
      ui="s"
    >
      Small
    </veui-checkbox>
    <veui-checkbox
      v-model="indeterminate"
      class="checkbox"
      ui="s"
    >
      Indeterminate
    </veui-checkbox>
  </section>
</article>
</template>

<script>
import { Checkbox } from 'veui'

export default {
  components: {
    'veui-checkbox': Checkbox
  },
  data () {
    return {
      checked: false,
      indeterminate: false,
      small: false
    }
  },
  computed: {
    size () {
      return this.small ? 's' : ''
    }
  }
}
</script>

<style lang="less" scoped>
.checkbox {
  & + & {
    margin-left: 20px;
  }
}
</style>

True/false values

You can set the v-model value by using the true-value and false-value props.

State: Not confirmed

Edit this demo on GitHubEdit
<template>
<article>
  <veui-checkbox
    v-model="status"
    true-value="CONFIRMED"
    false-value="UNCONFIRMED"
  >
    I've read the agreement
  </veui-checkbox>
  <p>State: {{ statusMap[status] }}</p>
</article>
</template>

<script>
import { Checkbox } from 'veui'

const STATUS_MAP = {
  CONFIRMED: 'Confirmed',
  UNCONFIRMED: 'Not confirmed'
}

export default {
  components: {
    'veui-checkbox': Checkbox
  },
  data () {
    return {
      status: 'UNCONFIRMED',
      statusMap: STATUS_MAP
    }
  }
}
</script>

API

Props

NameTypeDefaultDescription
uistring-

Preset styles.

ValueDescription
sSmall size style.
mMedium size style.
checkedbooleanfalse

.sync

Whether the checkbox is checked.

value*-When v-model is bound to an array, represents the value of the current checkbox.
true-value*trueThe value corresponding to the checked state.
false-value*falseThe value corresponding to the unchecked state.
indeterminatebooleanfalseWhether the checkbox is in the indeterminate state.
disabledbooleanfalseWhether the checkbox is disabled.
readonlybooleanfalseWhether the checkbox is readonly.

Slots

NameDescription
defaultThe descriptive text of the checkbox, which toggles the selection state when clicked. No default content.

Events

NameDescription
changeTriggered when the user toggles the selection state. The callback parameter is (checked: boolean). checked indicates whether the checkbox is currently selected.
input

v-model

Triggered after the selection state changes. The callback parameter is (val: *). val is the current v-model value. Unlike the change event, the input event is also triggered when the state changes due to data operations.

In addition, Checkbox supports the following native events:

auxclick, click, contextmenu, dblclick, mousedown, mouseenter, mouseleave, mousemove, mouseover, mouseout, mouseup, select, wheel, keydown, keypress, keyup, focus, blur, focusin, focusout.

The callback parameters are the corresponding native event objects.

Icons

NameDescription
checkedChecked state.
indeterminateIndeterminate state.
Edit this page on GitHubEdit
© Baidu, Inc. 2024