Skip to content

Checkbox

基础用法

html

<pa-checkbox v-model="checkValue">复选框</pa-checkbox>
<view class="text-28 text-black-3 mt-30">
  <text>当前选中值</text>
  <text class="ml-10">{{ JSON.stringify(checkValue) }}</text>
</view>
ts

import { ref } from 'vue'

const checkValue = ref(true)

半选状态

html

<pa-checkbox v-model="checkValue" indeterminate>复选框</pa-checkbox>
ts

import { ref } from 'vue'

const checkValue = ref(false)

复选框组

html

<pa-checkbox-group v-model="checkValue">
  <pa-checkbox v-for="item in options" :key="item.name" :name="item.name">
    {{ item.label }}
  </pa-checkbox>
</pa-checkbox-group>
<pa-checkbox-group v-model="checkValue" class="block mt-50">
  <pa-checkbox v-for="item in options" :key="item.name" :name="item.name" label-position="left">
    {{ item.label }}
  </pa-checkbox>
</pa-checkbox-group>
<view class="text-28 text-black-3 mt-30">
  <text>当前选中值</text>
  <text class="ml-10">{{ JSON.stringify(checkValue) }}</text>
</view>
ts

import { ref } from 'vue'

const checkValue = ref<number[]>([0])

const options = new Array(3).fill(0).map((_item, index) => ({
  name: index,
  label: '复选框' + index,
}))

水平方向

html

<pa-checkbox-group v-model="checkValue" direction="horizontal">
  <pa-checkbox v-for="item in options" :key="item.name" :name="item.name">
    {{ item.label }}
  </pa-checkbox>
</pa-checkbox-group>
<pa-checkbox-group v-model="checkValue" direction="horizontal" class="block mt-50">
  <pa-checkbox v-for="item in options" :key="item.name" :name="item.name" label-position="left">
    {{ item.label }}
  </pa-checkbox>
</pa-checkbox-group>
ts

import { ref } from 'vue'

const checkValue = ref<number[]>([0])

const options = new Array(3).fill(0).map((_item, index) => ({
  name: index,
  label: '复选框' + index,
}))

形状

html

<pa-checkbox-group v-model="checkValue">
  <pa-checkbox v-for="item in options" :key="item.name" :name="item.name" shape="square">
    {{ item.label }}
  </pa-checkbox>
</pa-checkbox-group>
ts

import { ref } from 'vue'

const checkValue = ref<number[]>([0])

const options = new Array(3).fill(0).map((_item, index) => ({
  name: index,
  label: '复选框' + index,
}))

禁用

html

<pa-checkbox-group v-model="checkValue">
  <pa-checkbox
    v-for="item in options"
    :key="item.name"
    :name="item.name"
    :disabled="item.name === 1"
  >
    {{ item.label }}
  </pa-checkbox>
</pa-checkbox-group>
<pa-checkbox-group v-model="checkValue" disabled class="block mt-50">
  <pa-checkbox v-for="item in options" :key="item.name" :name="item.name">
    {{ item.label }}
  </pa-checkbox>
</pa-checkbox-group>
ts

import { ref } from 'vue'

const checkValue = ref<number[]>([0])

const options = new Array(3).fill(0).map((_item, index) => ({
  name: index,
  label: '复选框' + index,
}))

限制最大可选数(2个)

html

<pa-checkbox-group v-model="checkValue" :max="2">
  <pa-checkbox v-for="item in options" :key="item.name" :name="item.name">
    {{ item.label }}
  </pa-checkbox>
</pa-checkbox-group>
ts

import { ref } from 'vue'

const checkValue = ref<number[]>([0])

const options = new Array(3).fill(0).map((_item, index) => ({
  name: index,
  label: '复选框' + index,
}))

Checkbox Props

参数说明类型默认值
modelValue是否选中boolean-
name标识符CheckboxValue''
shape形状'square'|'round''round'
disabled是否为禁用状态boolean-
labelDisabled是否禁用文本内容点击boolean-
labelPosition文本位置'left'|'right''right'
iconSize图标大小string | number'20px'
checkedColor选中状态颜色CSSProperties['color']-
indeterminate当前是否支持半选状态,一般用在全选操作中boolean-

CheckboxGroup Props

参数说明类型默认值
name标识符string''
modelValueCheckboxValue[]-
direction方向'horizontal'|'vertical''vertical'
disabled是否全部禁用boolean-
max限制选择的数量number-

Checkbox Event

事件名参数
update:modelValue(value: boolean)
change(value: boolean, name: CheckboxValue)

CheckboxGroup Event

事件名参数
update:modelValue(value: CheckboxValue[])
change(value: CheckboxValue[], name: string)

Checkbox Slot

名称说明
default-
default-

CheckboxGroup Slot

名称说明
default-

样式变量

名称默认值
--pa-checkbox-size20px
--pa-checkbox-displayflex
--pa-checkbox-margin0
--pa-checkbox-font-size16px
--pa-checkbox-label-colorvar(--pa-color-black)
--pa-checkbox-checked-colorvar(--pa-color-primary)
--pa-checkbox-checked-colorvar(--pa-color-primary)