Skip to content

Form 表单

表单主要提供统一的格式和表单的布局,可以通过设置表单的属性,统一表单内元素的样式

基础用法

vue




行内表单

当垂直方向空间受限且表单较简单时,可以在一行内放置表单。

通过设置 inline 属性,可以让表单域变为行内的表单域。

vue




对齐方式

根据你们的设计情况,来选择最佳的标签对齐方式。

通过设置 label-position 属性可以改变表单域标签的位置,可选值为 top、left, 当设为 top 时标签会置于表单域的顶部

vue




props

Form props

Form 组件可以设置一些属性,这些属性会影响到 Form 组件下所有的表单

name类型是否必传说明默认值
disabledbooleandisabled 所有表单输入undefined
inlinebooleaninline 模式所有的 FormItem 将在一行false
labelWidthnumber/stringlabel 的宽度,传数字自动加 px80
labelPosition'left', 'right', 'top'控制FormItemlabel 的位置'left'
labelAlign'top' | 'center' | 'bottom'FormItem 里 label 的垂直方向的对齐'top'

FormItem props

如果FormItem 中声明了和 Form同样的 props,将会覆盖 Form 的 props

name类型是否必传说明默认值
propstring用来做表单校验(待完善)undefined
requiredboolean是否必填false
offsetboolean在 label 为空时,labelPosition 不为 top 时 label 占用的宽度false
labelWidthnumber/stringlabel 的宽度,传数字自动加 px80
inlinebooleaninline 模式所有的 FormItem 将在一行false
labelPosition'left', 'right', 'top'控制FormItemlabel 的位置'left'
contentClassstring设置 FormItem 除了 label 之外的容器的 class''
labelAlign'top' | 'center' | 'bottom'FormItem 里 label 的垂直方向的对齐'top'

FormItemlabelWidth, inline, labelPosition可以覆盖Form的配置

TIP

如果在 Form 上设置了 disabled = true属性,使用 Form下面的所有 apathia 表单(如 Input, Checkbox)都会被 disabled, 除非你在 表单组件上设置 disabled 属性,默认表单组件的 props 优先级高于 form

html
<form disabled>
  <FormItem>
    <input :disabled="false" />
    <!-- won't be disabled -->
  </FormItem>

  <FormItem>
    <input />
    <!-- will be disabled -->
  </FormItem>
</form>

slots

插槽名称说明参数
default显示内容-
label内容 label,如果提供,将会覆盖 label prop-