XFom组件文档

572 阅读1分钟

XForm组件说明

使用配置化参数生成Form表单

参数

属性类型说明默认值
formOptionsArray,Function组件配置文件,使用BaseInput生成对应组件Input
inputWidthString,Number设置表单组件默认宽度100%
colSpanString当前item的Colspan属性24
others---iview组件文档中定义Form属性均可作为参数传入

formOptions参数

属性类型说明默认值
keyStringv-model绑定的属性名,当该项为slot和render函数渲染时只为循环渲染的key值
inputTypeString渲染的表单组件名称Input
itemLabelStringformItem的label名称
itemLabelWidthNumberformItem的label宽度
formItemOptionsObjectformItem的所有属性值对象
childrenOptionsObject,Array用于含有子组件的表单组件配置,比如Select,RadioGroup,CheckboxGroup等
requiredBoolean填写该属性开启快捷表单校验,不需要传rulesfalse
messageString表单校验提示语,配合required使用
formRenderFunction组件支持render函数渲染
clearableBoolean是否显示清除按钮true
formSlotNameString自定义组件插槽
others-iview组件文档中表单组件属性均可传入

方法

同iview form组件文档定义,比如this.$refs.XForm.validate()等于触发Form组件的validate方法

用法

::: demo

<template>
    <x-form
        v-model="formData"
        :form-options="formOptions"
        :input-width="200"
        :label-width="100"
    >
        <form-item slot="formItemSlot" label="年龄">
            <input-number style="width:200px" v-model="formData.number" />
        </form-item>
    </x-form>
</template>

<script>
export default {
  data() {
    return {
      formData: {},
      formOptions: [
        {
          key: 'name',
          itemLabel: '姓名',
          placeholder: '请输入姓名',
          required: true
        },
        {
          key: 'textarea',
          itemLabel: '备注',
          type: 'textarea',
          placeholder: '请输入',
          required: true,
          message: '请填写备注'
        },
        {
          key: 'status',
          itemLabel: '状态',
          inputType: 'Select',
          placeholder: '请选择状态',
          childrenOptions: [
            {
              label: '状态1',
              value: 'status1'
            },
            {
              label: '状态2',
              value: 'status2'
            }
          ]
        },
        {
          key: 'i-switch',
          itemLabel: '开关',
          inputType: 'i-switch'
        },
        {
          key: 'formSlot',
          formSlotName: 'formItemSlot'
        },
        {
            key: 'contactName',
            item: '姓名',
            formRender(h, { option, formData }) {
            return (
                    <Input
                        value={formData.contactName}
                        onInput={val => (formData.contactName = val)}
                        style="width:200px"
                    >
                    </Input>
                )
            }
        }
      ]
    }
  }
}
</script>

:::