更新记录

1.2.3(2022-11-11)

  • 优化bug

1.2.1(2021-03-17)

更新最大宽度

1.2(2021-03-17)

  • 支持多选+other
查看更多

平台兼容性

Vue2 Vue3
×
App 快应用 微信小程序 支付宝小程序 百度小程序 字节小程序 QQ小程序
HBuilderX 3.1.0 app-vue app-nvue
钉钉小程序 快手小程序 飞书小程序 京东小程序
× × × ×
H5-Safari Android Browser 微信浏览器(Android) QQ浏览器(Android) Chrome IE Edge Firefox PC-Safari
× ×

简介

正常情况下使用单选/多选方式(uni-data-checkbox),只能选择这个列表内的数据,如果有个选项是其他,要求可以输入文字就不能满足了,
此控件是基于官方的uni-data-checkbox增加了一个“其他”选项扩展,更详细的文档请查看官方文档

插件特有属性

属性名 类型 可选值 默认值 说明
placeholder String - 请输入其他选项 其他选项占位说明
otherName String - 其他 其他选项的名称

官方默认属性

属性名 类型 可选值 默认值 说明
value/v-model Array/String/Number - - 默认值,multiple=true时为 Array类型,否则为 String或Number类型
localdata Array - - 本地渲染数据
mode String default/list/button/tag default 显示模式
multiple Boolean - false 是否多选
min String/Number - - 最小选择个数 ,multiple为true时生效
max String/Number - - 最大选择个数 ,multiple为true时生效
wrap Boolean - - 是否换行显示
icon String left/right left list 列表模式下 icon 显示的位置
selectedColor String - #007aff 选中颜色
selectedTextColor String - #333 选中文本颜色,如不填写则自动显示
emptyText String - 暂无数据 没有数据时显示的文字 ,本地数据无效
map Object - {text:'text',value:'value'} 字段映射,将text/value映射到数据中的其他字段

绑定事件

事件名 事件说明 返回参数
@change 选中或输入状态改变时触发事件 {detail:{value:""}}
@input 选中或输入状态改变时触发事件 String/Array

使用效果

范例

完整示例

<template>
    <view>
        <uni-forms ref="form" :value="formData" validate-trigger="submit" err-show-type="toast" labelWidth="100"
            labelPosition="top">
            <view class="">
                <text>本地数据示例</text>
            </view>
            <uni-forms-item name="tag_unit" label="1.正常单选">
                <cloud-data-checkbox-other mode="tag" v-model="formData.tag_unit" :localdata="units"
                    @change="chageResult" @input="chageResultInput">
                </cloud-data-checkbox-other>
            </uni-forms-item>
            <uni-forms-item name="tag_unit10" label="1-1.正常单选,自动添加其他选项">
                <cloud-data-checkbox-other mode="tag" v-model="formData.tag_unit10" :localdata="units2"
                    @change="chageResult" @input="chageResultInput">
                </cloud-data-checkbox-other>
            </uni-forms-item>
            <uni-forms-item name="tag_unit11" label="2.其他单选">
                <cloud-data-checkbox-other mode="tag" v-model="formData.tag_unit11" :localdata="units"
                    @change="chageResult" @input="chageResultInput">
                </cloud-data-checkbox-other>
            </uni-forms-item>
            <uni-forms-item name="tag_unit2" label="3.正常多选">
                <cloud-data-checkbox-other mode="tag" multiple v-model="formData.tag_unit2" :localdata="units"
                    @change="chageResult" @input="chageResultInput">
                </cloud-data-checkbox-other>
            </uni-forms-item>
            <uni-forms-item name="tag_unit22" label="4.其他多选">
                <cloud-data-checkbox-other mode="tag" multiple v-model="formData.tag_unit22" :localdata="units"
                    @change="chageResult" @input="chageResultInput">
                </cloud-data-checkbox-other>
            </uni-forms-item>
            <uni-forms-item name="tag_unit221" label="5.正常+其他多选">
                <cloud-data-checkbox-other mode="tag" multiple v-model="formData.tag_unit221" :localdata="units"
                    @change="chageResult" @input="chageResultInput">
                </cloud-data-checkbox-other>
            </uni-forms-item>

            <view class="" style="margin-top: 30px;">
                <text>查询数据库示例,如果后台没有“opendb-city-china”表,需要先添加一次,此表仅为测试表,可以根据自己需求,改成其他表</text>
            </view>
            <uni-forms-item name="city1" label="7.城市单选">
                <cloud-data-checkbox-other mode="tag" v-model="formData.city1" collection="opendb-city-china"
                    field="name as text,name as value" where="parent_code=='110100'" :pageSize="5" @change="chageResult"
                    @input="chageResultInput">
                </cloud-data-checkbox-other>
            </uni-forms-item>
            <uni-forms-item name="city2" label="8.城市多选">
                <cloud-data-checkbox-other mode="tag" multiple v-model="formData.city2" collection="opendb-city-china"
                    field="name as text,name as value" where="parent_code=='110100'" :pageSize="5" @change="chageResult"
                    @input="chageResultInput">
                </cloud-data-checkbox-other>
            </uni-forms-item>
            <view class="">
                <text>{{result}}</text>
            </view>
            <view class="uni-button-group" style="margin-top: 30px;">
                <button type="primary" class="uni-button" @click="submit">获取表单</button>
            </view>
        </uni-forms>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                formData: {
                    tag_unit: "份",
                    tag_unit10: "份",
                    tag_unit11: "吨",
                    tag_unit2: "份",
                    tag_unit22: ["Kg"],
                    city1: "",
                    city2: "",
                    tag_unit221: ["份", "Kg"],
                },
                result: "点击获取表单,得到最终数据"
            };
        },
        computed: {
            units() {
                let otherOption = {
                    text: "其他",
                    is_other: true,
                    value: "其他"
                };
                return [{
                    text: "份",
                    value: "份"
                }, otherOption]
            },
            units2() {
                return [{
                    text: "份",
                    value: "份"
                }]
            },
        },
        methods: {
            chageResult(e) {
                console.log("chageResult", e)
            },
            chageResultInput(e) {
                console.log("chageResultInput", e)
            },
            submit() {
                this.$refs.form.validate().then((res) => {
                    console.log("result", res)
                    this.result = JSON.stringify(res, null, 4)
                }).catch((errors) => {
                    uni.hideLoading()
                })
            }
        }
    }
</script>

<style lang="scss">

</style>

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT协议

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问