mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-05 05:42:44 +08:00
docs: add useCustomFieldValue document (#9202)
This commit is contained in:
parent
1bfcbab2fa
commit
5852b80a17
50
docs/markdown/use-custom-field-value.en-US.md
Normal file
50
docs/markdown/use-custom-field-value.en-US.md
Normal file
@ -0,0 +1,50 @@
|
||||
# useCustomFieldValue
|
||||
|
||||
### Intro
|
||||
|
||||
Used to custom Field value.
|
||||
|
||||
## Usage
|
||||
|
||||
### Basic Usage
|
||||
|
||||
If you want to custom Form items, you can insert your component into the `input` slot of the Field component, and call the `useCustomFieldValue` method inside your custom component.
|
||||
|
||||
#### MyComponent
|
||||
|
||||
```js
|
||||
// MyComponent.vue
|
||||
import { useCustomFieldValue } from '@vant/use';
|
||||
|
||||
export default {
|
||||
setup() {
|
||||
useCustomFieldValue(() => 'Some value');
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
#### Form
|
||||
|
||||
```html
|
||||
<van-form>
|
||||
<van-field name="my-field" label="Custom Field">
|
||||
<template #input>
|
||||
<my-component />
|
||||
</template>
|
||||
</van-field>
|
||||
</van-form>
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### Type Declarations
|
||||
|
||||
```ts
|
||||
function useCustomFieldValue(customValue: () => unknown): void;
|
||||
```
|
||||
|
||||
### Params
|
||||
|
||||
| Name | Description | Type | Default Value |
|
||||
| ----------- | --------------------------- | --------------- | ------------- |
|
||||
| customValue | Function to get field value | _() => unknown_ | - |
|
57
docs/markdown/use-custom-field-value.zh-CN.md
Normal file
57
docs/markdown/use-custom-field-value.zh-CN.md
Normal file
@ -0,0 +1,57 @@
|
||||
# useCustomFieldValue
|
||||
|
||||
### 介绍
|
||||
|
||||
用于自定义 Form 组件中的表单项。
|
||||
|
||||
## 代码演示
|
||||
|
||||
### 基本用法
|
||||
|
||||
如果需要自定义表单项,可以在 Field 组件的 `input` 插槽中插入你的自定义组件,并在自定义组件内部调用 `useCustomFieldValue` 方法。
|
||||
|
||||
#### 自定义组件
|
||||
|
||||
首先,在你的自定义组件中,调用 `useCustomFieldValue` 方法,并传入一个回调函数,这个函数返回值为表单项的值。
|
||||
|
||||
```js
|
||||
// MyComponent.vue
|
||||
import { useCustomFieldValue } from '@vant/use';
|
||||
|
||||
export default {
|
||||
setup() {
|
||||
// 此处传入的值会替代 Field 组件内部的 value
|
||||
useCustomFieldValue(() => 'Some value');
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
#### 表单
|
||||
|
||||
接着,在 Form 组件中嵌入你的自定义组件,当提交表单时,即可获取到自定义表单项的值。
|
||||
|
||||
```html
|
||||
<van-form>
|
||||
<!-- 这是一个自定义表单项 -->
|
||||
<!-- 当表单提交时,会包括 useCustomFieldValue 中传入的值 -->
|
||||
<van-field name="my-field" label="自定义表单项">
|
||||
<template #input>
|
||||
<my-component />
|
||||
</template>
|
||||
</van-field>
|
||||
</van-form>
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### 类型定义
|
||||
|
||||
```ts
|
||||
function useCustomFieldValue(customValue: () => unknown): void;
|
||||
```
|
||||
|
||||
### 参数
|
||||
|
||||
| 参数 | 说明 | 类型 | 默认值 |
|
||||
| ----------- | ------------------ | --------------- | ------ |
|
||||
| customValue | 获取表单项值的函数 | _() => unknown_ | - |
|
@ -600,3 +600,9 @@ formRef.value?.submit();
|
||||
| 名称 | 说明 |
|
||||
| ------- | -------- |
|
||||
| default | 表单内容 |
|
||||
|
||||
## 常见问题
|
||||
|
||||
### 如何自定义表单项?
|
||||
|
||||
Vant 支持在 Form 组件中插入自定义的表单项,具体用法参见 [useCustomFieldValue](/zh-CN/use-custom-field-value)。
|
||||
|
@ -425,6 +425,10 @@ module.exports = {
|
||||
path: 'use-count-down',
|
||||
title: 'useCountDown',
|
||||
},
|
||||
{
|
||||
path: 'use-custom-field-value',
|
||||
title: 'useCustomFieldValue',
|
||||
},
|
||||
{
|
||||
path: 'use-rect',
|
||||
title: 'useRect',
|
||||
@ -835,6 +839,10 @@ module.exports = {
|
||||
path: 'use-count-down',
|
||||
title: 'useCountDown',
|
||||
},
|
||||
{
|
||||
path: 'use-custom-field-value',
|
||||
title: 'useCustomFieldValue',
|
||||
},
|
||||
// {
|
||||
// path: 'use-rect',
|
||||
// title: 'useRect',
|
||||
|
Loading…
x
Reference in New Issue
Block a user