表单

基础用法

  • 示例:
点击查看代码
<template>
  <z-form
    :model="formState"
    name="basic"
    :label-col="{ span: 8 }"
    :wrapper-col="{ span: 16 }"
    autocomplete="off"
    @finish="onFinish"
    @finishFailed="onFinishFailed"
  >
    <z-form-item
      label="Username"
      name="username"
      :rules="[{ required: true, message: 'Please input your username!' }]"
    >
      <z-input v-model:value="formState.username" />
    </z-form-item>

    <z-form-item
      label="Password"
      name="password"
      :rules="[{ required: true, message: 'Please input your password!' }]"
    >
      <z-password v-model:value="formState.password" />
    </z-form-item>

    <z-form-item name="remember" :wrapper-col="{ offset: 8, span: 16 }">
      <z-checkbox v-model:checked="formState.remember">Remember me</z-checkbox>
    </z-form-item>

    <z-form-item :wrapper-col="{ offset: 8, span: 16 }">
      <z-button type="primary" html-type="submit">Submit</z-button>
    </z-form-item>
  </z-form>
</template>
<script lang="ts">
import { defineComponent, reactive } from 'vue';

interface FormState {
  username: string;
  password: string;
  remember: boolean;
}
export default defineComponent({
  setup() {
    const formState = reactive<FormState>({
      username: '',
      password: '',
      remember: true,
    });
    const onFinish = (values: any) => {
      console.log('Success:', values);
    };

    const onFinishFailed = (errorInfo: any) => {
      console.log('Failed:', errorInfo);
    };
    return {
      formState,
      onFinish,
      onFinishFailed,
    };
  },
});
</script>

共同的 API

参数说明类型默认值
allowClear是否显示清楚按钮booleantrue
autofocus自动获取焦点booleanfalse
bordered是否有边框booleanfalse
dateRender自定义日期单元格的内容v-slot:dateRender="{current, today}"-
disabled禁用booleanfalse
disabledDate不可选择的日期(currentDate: dayjs) => boolean-
dropdownClassName额外的弹出日历 classNamestring-
getPopupContainer定义浮层的容器,默认为 body 上新建 div定义浮层的容器,默认为 body 上新建 div-
inputReadOnly设置输入框为只读(避免在移动设备上打开虚拟键盘)booleanfalse
getPopupContainer定义浮层的容器,默认为 body 上新建 divfunction(trigger)-
mode日期面板的状态time | date | month | year | decadetrue
open控制弹层是否展开boolean-
picker设置选择器类型date | week | month | quarter | yeardate
placeholder输入框提示文字string | [string, string]-
popupStyle额外的弹出日历样式CSSProperties-
size输入框大小,large 高度为 40px,small 为 24px,默认是 32pxlarge | middle | small-
suffixIcon自定义的选择框后缀图标v-slot:suffixIcon-
valueFormat可选,绑定值的格式,对 value、defaultValue、defaultPickerValue 起作用。不指定则绑定值为 dayjs 对象string-

共有的事件

事件说明回调参数
openChange弹出日历和关闭日历的回调function(status)
panelChange日期面板变化时的回调function(value, mode)

共同的方法

事件说明
blur()focus()
Last Updated:
Contributors: jixuanyu