Skip to content

Checkbox

The check box component is generally used in scenarios that require multiple selections. This component has complete functions and is easy to use

platform compatibility

App(vue)App(nvue)H5小程序VUE2VUE3

basic use

vue
<template>
    <view>
        <wu-checkbox-group
            v-model="checkboxValue1"
            placement="column"
            @change="checkboxChange"
        >
            <wu-checkbox
                :customStyle="{marginBottom: '8px'}"
                v-for="(item, index) in checkboxList1"
                :key="index"
                :label="item.name"
                :name="item.name"
            >
            </wu-checkbox>
        </wu-checkbox-group>
    </view>
</template>
<script>
export default {
    data() {
        return {
            checkboxValue1:[],
            // Basic case data
            checkboxList1: [{
                    name: 'apple',
                    disabled: false
                },
                {
                    name: 'banana',
                    disabled: false
                },
                {
                    name: 'orange',
                    disabled: false
                }
            ],
        }

    },
    methods: {
        checkboxChange(n) {
            console.log('change', n);
        }
    }
}
</script>
<template>
    <view>
        <wu-checkbox-group
            v-model="checkboxValue1"
            placement="column"
            @change="checkboxChange"
        >
            <wu-checkbox
                :customStyle="{marginBottom: '8px'}"
                v-for="(item, index) in checkboxList1"
                :key="index"
                :label="item.name"
                :name="item.name"
            >
            </wu-checkbox>
        </wu-checkbox-group>
    </view>
</template>
<script>
export default {
    data() {
        return {
            checkboxValue1:[],
            // Basic case data
            checkboxList1: [{
                    name: 'apple',
                    disabled: false
                },
                {
                    name: 'banana',
                    disabled: false
                },
                {
                    name: 'orange',
                    disabled: false
                }
            ],
        }

    },
    methods: {
        checkboxChange(n) {
            console.log('change', n);
        }
    }
}
</script>

Custom shape

  • You can set the checkbox to be square or circle by setting shape to square or circle
vue
<template>
    <view>
        <wu-checkbox-group
            v-model="checkboxValue1"
            placement="column"
            shape="circle"
            @change="checkboxChange"
        >
            <wu-checkbox
                :customStyle="{marginBottom: '8px'}"
                v-for="(item, index) in checkboxList1"
                :key="index"
                :label="item.name"
                :name="item.name"
            >
            </wu-checkbox>
        </wu-checkbox-group>
    </view>
</template>
<script>
export default {
    data() {
        return {
            checkboxValue1:[],
            // Basic case data
            checkboxList1: [{
                    name: 'apple',
                    disabled: false
                },
                {
                    name: 'banana',
                    disabled: false
                },
                {
                    name: 'orange',
                    disabled: false
                }
            ],
        }

    },
    methods: {
        checkboxChange(n) {
            console.log('change', n);
        }
    }
}
</script>
<template>
    <view>
        <wu-checkbox-group
            v-model="checkboxValue1"
            placement="column"
            shape="circle"
            @change="checkboxChange"
        >
            <wu-checkbox
                :customStyle="{marginBottom: '8px'}"
                v-for="(item, index) in checkboxList1"
                :key="index"
                :label="item.name"
                :name="item.name"
            >
            </wu-checkbox>
        </wu-checkbox-group>
    </view>
</template>
<script>
export default {
    data() {
        return {
            checkboxValue1:[],
            // Basic case data
            checkboxList1: [{
                    name: 'apple',
                    disabled: false
                },
                {
                    name: 'banana',
                    disabled: false
                },
                {
                    name: 'orange',
                    disabled: false
                }
            ],
        }

    },
    methods: {
        checkboxChange(n) {
            console.log('change', n);
        }
    }
}
</script>

disable checkbox

Set disabled to true to disable a component so that users cannot click it. There are two states of disabling. One is to disable before it is checked, and only a gray area is displayed at this time. The second is to disable it after it has been checked, there will be a gray checked icon, but it is still inoperable at this time.

vue
<template>
    <view>
        <wu-checkbox-group
            v-model="checkboxValue1"
            placement="column"
            @change="checkboxChange"
        >
            <wu-checkbox
                :customStyle="{marginBottom: '8px'}"
                v-for="(item, index) in checkboxList1"
                :key="index"
                :label="item.name"
                :name="item.name"
                :disabled="item.disabled"
            >
            </wu-checkbox>
        </wu-checkbox-group>
    </view>
</template>
<script>
export default {
    data() {
        return {
            checkboxValue1:[],
            // Basic case data
            checkboxList1: [{
                    name: 'apple',
                    disabled: false
                },
                {
                    name: 'banana',
                    disabled: false
                },
                {
                    name: 'orange',
                    disabled: true
                }
            ],
        }

    },
    methods: {
        checkboxChange(n) {
            console.log('change', n);
        }
    }
}
</script>
<template>
    <view>
        <wu-checkbox-group
            v-model="checkboxValue1"
            placement="column"
            @change="checkboxChange"
        >
            <wu-checkbox
                :customStyle="{marginBottom: '8px'}"
                v-for="(item, index) in checkboxList1"
                :key="index"
                :label="item.name"
                :name="item.name"
                :disabled="item.disabled"
            >
            </wu-checkbox>
        </wu-checkbox-group>
    </view>
</template>
<script>
export default {
    data() {
        return {
            checkboxValue1:[],
            // Basic case data
            checkboxList1: [{
                    name: 'apple',
                    disabled: false
                },
                {
                    name: 'banana',
                    disabled: false
                },
                {
                    name: 'orange',
                    disabled: true
                }
            ],
        }

    },
    methods: {
        checkboxChange(n) {
            console.log('change', n);
        }
    }
}
</script>

Custom Colors

The color referred to here is the background color when checkbox is selected, and the parameter is activeColor

html
<wu-checkbox-group v-model="checked">
	<wu-checkbox  activeColor="red" label="light and shadow"></wu-checkbox>
</wu-checkbox-group>
<wu-checkbox-group v-model="checked">
	<wu-checkbox  activeColor="red" label="light and shadow"></wu-checkbox>
</wu-checkbox-group>

Horizontal arrangement

You can set the checkboxes to be arranged horizontally or vertically by setting placement to row or column.

html
<wu-checkbox-group v-model="checked" placement="row">
	<wu-checkbox activeColor="red" label="red"></wu-checkbox>
	<wu-checkbox activeColor="green" label="green"></wu-checkbox>
</wu-checkbox-group>
<wu-checkbox-group v-model="checked" placement="row">
	<wu-checkbox activeColor="red" label="red"></wu-checkbox>
	<wu-checkbox activeColor="green" label="green"></wu-checkbox>
</wu-checkbox-group>

Horizontal two ends arrangement form

You can set the alignment of the checkbox icon to be left or right by setting iconPlacement to left or right

html
<wu-checkbox-group 
    v-model="checked"
    iconPlacement="right" 
    placement="row">
	<wu-checkbox activeColor="red" label="red"></wu-checkbox>
	<wu-checkbox activeColor="green" label="green"></wu-checkbox>
</wu-checkbox-group>
<wu-checkbox-group 
    v-model="checked"
    iconPlacement="right" 
    placement="row">
	<wu-checkbox activeColor="red" label="red"></wu-checkbox>
	<wu-checkbox activeColor="green" label="green"></wu-checkbox>
</wu-checkbox-group>

API

Checkbox Props

Note: Among radio and radio-group parameters with the same name, the radio parameter has a higher priority.

property namedescriptiontypedefault valueoptional values ​​
namethe name of the checkboxString / Number--
shapeshape, square is a square, circle is a circleStringsquaresquare / circle
sizeoverall sizeString / Number--
checkedwhether it is checked by defaultBooleanfalsetrue / false
disabledWhether to disableBoolean--
activeColorThe color in the selected state, if this value is set, it will override the parent's activeColor valueString--
inactiveColorinactive colorString--
iconSizeThe size of the icon, in pxString / Number--
iconColoricon colorString--
labellabel prompt text, because under nvue, the text directly slotted in, due to the special structure, the style cannot be modifiedString / Number--
labelSizefont size of the label, in pxString / Number--
labelColorthe color of the labelString--
labelDisabledWhether to disable clicking on the prompt to select the checkboxString / Boolean--

CheckboxGroup Props

property namedescriptiontypedefault valueoptional values ​​
nameidentifierString--
value / modelValueBinding valueString / Number / Boolean''-
shapeshape, circle-circle, square-squareStringcirclecircle / square
disabledWhether to disable all radiosBooleanfalsetrue
activeColorThe color in the selected state, if the sub-component sets this value, it will overwrite this valueString#2979ff-
inactiveColorInactive colorString#c8c9cc-
sizeThe size of the entire component, default pxString / Number18-
placementlayout method, row-horizontal, column-verticalStringrowcolumn
labelSizefont size of the label, in pxString / Number14-
labelColorfont color of labelString#303133-
labelDisabledWhether to disable clicking on the textBooleanfalsetrue / false
iconColoricon colorString#ffffff-
iconSizeThe size of the icon, in pxString / Number12-
iconPlacementThe alignment of the check icon, left-left, right-rightStringleftleft / right
borderBottomWhether to display an underline when vertically arranging columnsBooleanfalsetrue / false

CheckboxGroup Event

method namedescriptioncallback parameters
changeTriggered when any checkbox state changesdetail = array( [element is the name of the selected checkbox] )
Slot NameDescription
defaultcustom content
iconCustom selected icon