# formily-vue **Repository Path**: hashplus/formily-vue ## Basic Information - **Project Name**: formily-vue - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2021-03-25 - **Last Updated**: 2023-12-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # @formily/vue > Formily 在 vue(v2.x) 层的实现,内置表单状态核心管理(@formily/core), 依赖@vue/composition-api > @formily/vue 中主要包含了以下部分: > > - Form 表单容器 > - Field 表单字段 > - VirtualField 虚拟表单字段 > - FormaSpy 表单替身 > - FormProvider 表单核心提供者 > - FormConsumer 表单核心消费者(即将废弃,请使用 FormSpy) > - createFormActions 创建表单核心操作 API 实例 > - createAsyncFormActions 创建表单核心操作 API 实例(异步) > - FormEffectHooks 表单生命周期 hook ### 安装 ```bash npm install --save @formily/vue ``` ### 目录 - [使用方式](#使用方式) - [`快速开始`](#快速开始) - [`基础类型字段`](#基础类型字段) - [`字段校验`](#字段校验) - [`对象类型字段`](#对象类型字段) - [`简单数组类型字段`](#简单数组类型字段) - [`对象数组类型字段`](#对象数组类型字段) - [`display与visible`](#display-visible) - [`简单联动`](#简单联动) - [`异步联动`](#异步联动) - [`联动校验`](#联动校验) - [`复杂联动`](#复杂联动) - [`复用Effects`](#复用Effects) - [`combo字段`](#combo字段) - [`跨文件消费表单数据`](#跨文件消费表单数据) ### 使用方式 #### 使用前置 依赖@vue/composition-api, 需要提前引入。 ```javascript import App from './App.vue' import VueCompositionAPI from '@vue/composition-api' Vue.use(VueCompositionAPI) ``` #### 快速开始 ```html ``` #### 基础类型字段 示例:以输入框为例,如何快速绑定表单字段,后续例子都基于此字段拓展。 ```html ``` #### 字段校验 示例:必填校验 + error 类型校验 + warning 类型校验 + 自定义校验 校验的类型可以是 [ValidatePatternRules](#ValidatePatternRules),即 [InternalFormats](#InternalFormats) | [CustomValidator](#CustomValidator) | [ValidateDescription](#ValidateDescription) | [ValidateArrayRules](#ValidateArrayRules) InputField: ```html ``` Form: ```html ``` #### 对象类型字段 示例:用户信息 `user(username, age)` InputField: ```html ``` Form: ```html ``` #### 简单数组类型字段 示例:用户 id 列表,增删改查 InputField: ```html ``` Form: ```html ``` #### 对象数组类型字段 示例:用户 id 列表,增删改查 InputField: ```html ``` Form: ```html ``` #### display visible 示例: display 与 visible 对 values 的影响 InputField: ```html ``` CheckedField: ```html ``` Form: ```html ``` #### 简单联动 示例:显示及隐藏,修改 props 和 value InputField: ```html ``` CheckedField: ```html ``` Form: ```html ``` #### 异步联动 示例:异步切换 select 的 dataSource CheckedField: ```html ``` SelectField: ```html ``` Form: ```html ``` #### 联动校验 示例:初始化校验,字段 change 时自动重新触发校验 InputField: ```html ``` Form: ```html ``` #### 复杂联动 示例:ArrayField 复杂联动 InputField: ```html ``` Form: ```html ``` #### 复用 Effects 自定义可复用的 effects InputField: ```html ``` CheckedField: ```html ``` Form: ```html ``` #### combo 字段 示例:combo username 和 age 字段, 更多用法,请点击[FormSpy](#FormSpy)查看 InputField: ```html ``` Form: ```html ``` #### 跨文件消费表单数据 ```typescript 文件目录 --app |---components |---customForm ``` 示例:跨文件消费表单数据, 更多用法,请参考[FormProvider](#FormProvider) 和 [FormSpy](#FormSpy) InputField: ```html ``` CustomForm: ```html ``` FormProvider: ```html ```