0.1.0 • Published 7 years ago

sf-form v0.1.0

Weekly downloads
41
License
-
Repository
-
Last release
7 years ago

七鱼form组件

基础用法

:::ysfdoc sf-form组件 包括 input checkbox radio switch form验证

<sf-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="ruleForm">
      <sf-form-item label="Title" prop="name">
        <sf-input v-model="ruleForm.name"></sf-input>
      </sf-form-item>
      <sf-form-item label="Checkbox" prop="city">
        <sf-checkbox-group v-model="ruleForm.city">
          <sf-checkbox v-for="item in cities" :label="item.key">{{item.value}}</sf-checkbox>
        </sf-checkbox-group>
      </sf-form-item>
      <sf-form-item label="Radio" prop="radio">
        <sf-radio-group v-model="ruleForm.radio">
          <sf-radio label="1">Radio1</sf-radio>
          <sf-radio label="2">Radio2</sf-radio>
        </sf-radio-group>
      </sf-form-item>
      <sf-form-item label="Textarea" prop="textarea">
        <sf-input type="textarea" :autosize="true" v-model="ruleForm.textarea"></sf-input>
      </sf-form-item>
      <sf-form-item label="Switch" prop="switch">
        <sf-switch v-model="ruleForm.switch" ></sf-switch>
      </sf-form-item>
      <sf-form-item>
        <sf-button @click.native="submitForm('ruleForm')">立即创建</sf-button>
        <sf-button @click.native="resetForm('ruleForm')">重置</sf-button>
      </sf-form-item>
    </sf-form>
    <script>
  export default {
    name: 'app',
    data(){
      return {
        cities: [
          {key: 1, value: "北京"},
          {key: 2, value: "上海"},
          {key: 3, value: "天津"},
          {key: 4, value: "杭州"},
        ],
        ruleForm: {
          name: '',
          city: [],
          radio: '',
          textarea: '',
          switch:true
        },
        rules: {
          name: [
            {required: true, message: '请输入title', trigger: 'blur'},
            {min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur'}
          ],
          city: [
            {type: 'array', required: true, message: '请选择city', trigger: 'change'}
          ],
          radio: [
            {required: true, message: '请选择radio', trigger: 'change'}
          ],
          textarea: [
            {required: true, message: '请填写textarea', trigger: 'blur'}
          ]
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            console.log(this.ruleForm);
          } else {
            console.log('error');
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>

:::

Form Attributes

参数说明类型可选值默认值
model表单数据对象object
rules表单验证规则object
inline行内表单模式booleanfalse
label-position表单域标签的位置stringright/left/topright
label-width表单域标签的宽度,所有的 form-item 都会继承 form 组件的 labelWidth 的值string
label-suffix表单域标签的后缀string
show-message是否显示校验错误信息booleantrue

Form Methods

方法名说明参数
validate对整个表单进行校验的方法Function(callback: Function(boolean))
validateField对部分表单字段进行校验的方法Function(prop: string, callback: Function(errorMessage: string))
resetFields对整个表单进行重置,将所有字段值重置为空并移除校验结果-

Form-Item Attributes

参数说明类型可选值默认值
prop表单域 model 字段string传入 Form 组件的 model 中的字段
label标签文本string
label-width表单域标签的的宽度,例如 '50px'string
required是否必填,如不设置,则会根据校验规则自动生成boleanfalse
rules表单验证规则object
error表单域验证错误信息, 设置该值会使表单验证状态变为error,并显示该错误信息string
show-message是否显示校验错误信息booleantrue

Input Attributes

参数说明类型可选值默认值
type类型stringtext/textareatext
value绑定值string, number
maxlength最大输入长度number
minlength最小输入长度number
placeholder输入框占位文本string
disabled禁用booleanfalse
size输入框尺寸,只在 type!="textarea" 时有效stringlarge, small, mini
rows输入框行数,只对 type="textarea" 有效number2
autosize自适应内容高度,只对 type="textarea" 有效,可传入对象,如,{ minRows: 2, maxRows: 6 }boolean/objectfalse
auto-complete原生属性,自动补全stringon, offoff
name原生属性string
max原生属性,设置最大值*
min原生属性,设置最小值*
resize控制是否能被用户缩放stringnone, both, horizontal, vertical
autofocus原生属性,自动获取焦点booleantrue, falsefalse

Input Events

事件名称说明回调参数
blur在 Input 失去焦点时触发(event: Event)
focus在 Input 获得焦点时触发(event: Event)
change在 Input 值改变时触发(value: string | number)

Radio Attributes

参数说明类型可选值默认值
labelRadio 的 valuestring,number
disabled是否禁用booleanfalse
name原生 name 属性string

Radio-group Attributes

参数说明类型可选值默认值
sizeRadio 按钮组尺寸stringlarge, small
fill按钮激活时的填充色和边框色string#20a0ff
text-color按钮激活时的文本颜色string#ffffff

Radio-group Events

事件名称说明回调参数
change绑定值变化时触发的事件选中的 Radio label 值

Radio-button Attributes

参数说明类型可选值默认值
labelRadio 的 valuestring,number
disabled是否禁用booleanfalse

Attributes

参数说明类型可选值默认值
disabled是否禁用booleanfalse
widthswitch 的宽度(像素)number166(有文字)/ 158(无文字)
on-textswitch 打开时的文字string启用
off-textswitch 关闭时的文字string停用
on-colorswitch 打开时的背景色string#20A0FF
off-colorswitch 关闭时的背景色string#C0CCDA
nameswitch 对应的 name 属性string

Events

事件名称说明回调参数
changeswitch 状态发生变化时的回调函数新状态的布尔值

Checkbox Attributes

参数说明类型可选值默认值
label选中状态的值(只有在checkbox-group或者绑定对象类型为array时有效)string
true-label选中时的值string, number
false-label没有选中时的值string, number
name原生 name 属性string
disabled按钮禁用booleanfalse
checked当前是否勾选booleanfalse
indeterminate设置 indeterminate 状态,只负责样式控制booleanfalse

Checkbox-group Events

事件名称说明回调参数
change当绑定值变化时触发的事件event 事件对象
0.1.0

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago