|
5 | 5 | ## 演示 |
6 | 6 |
|
7 | 7 | <script setup lang="ts"> |
8 | | - import { reactive, watch, ref } from 'vue' |
| 8 | + import { reactive, watch, ref, computed } from 'vue' |
9 | 9 | import { FormItem, Input, Form, Button, useFormReset } from '../../src' |
| 10 | + import RadioGroup from '../../src/components/radio/RadioGroup.vue' |
| 11 | + import Radio from '../../src/components/radio/Radio.vue' |
| 12 | + |
| 13 | + const formAlign = ref('right') |
| 14 | + const formItemAlign = ref('null') |
| 15 | + |
| 16 | + const itemAlign = computed(() => { |
| 17 | + return formItemAlign.value === 'null' ? null : formItemAlign.value |
| 18 | + }) |
10 | 19 |
|
11 | 20 | const { formFields, resetFields } = useFormReset({ |
12 | 21 | username: '', |
|
148 | 157 | </nt-form-item> |
149 | 158 | </textarea> |
150 | 159 | </CodePreview> |
151 | | -</ClientOnly>` |
| 160 | +</ClientOnly> |
| 161 | + |
| 162 | +### 对齐方式 |
| 163 | + |
| 164 | +通过设置 `label-position` 来应用标签和内容的对齐方式。 |
| 165 | + |
| 166 | +您可以分别设置 `nt-form-item` 的 `label-position`. 如果值为空, 则会使用 `nt-form` 的 `label-position`。 |
| 167 | + |
| 168 | +<ClientOnly> |
| 169 | + <CodePreview> |
| 170 | + <textarea lang="vue-html" v-pre> |
| 171 | + <nt-form label-position="right"> |
| 172 | + <nt-form-item label="用户名"> |
| 173 | + <nt-input placeholder="请输入用户名"></nt-input> |
| 174 | + </nt-form-item> |
| 175 | + <nt-form-item label="密码"> |
| 176 | + <nt-input placeholder="请输入密码"></nt-input> |
| 177 | + </nt-form-item> |
| 178 | + <nt-form-item> |
| 179 | + <nt-button html-type="submit">提交</nt-button> |
| 180 | + </nt-form-item> |
| 181 | + </nt-form> |
| 182 | + </textarea> |
| 183 | + <template #preview> |
| 184 | + <Form label-width="120px" :label-position="formAlign"> |
| 185 | + <FormItem label="FormAlign" :label-position="itemAlign"> |
| 186 | + <RadioGroup v-model="formAlign"> |
| 187 | + <Radio label="Left" value="left" type="button" /> |
| 188 | + <Radio label="Right" value="right" type="button" /> |
| 189 | + <Radio label="Top" value="top" type="button" /> |
| 190 | + </RadioGroup> |
| 191 | + </FormItem> |
| 192 | + <FormItem label="FormItemAlign" :label-position="itemAlign"> |
| 193 | + <RadioGroup v-model="formItemAlign"> |
| 194 | + <Radio label="Null" value="null" type="button" /> |
| 195 | + <Radio label="Left" value="left" type="button" /> |
| 196 | + <Radio label="Right" value="right" type="button" /> |
| 197 | + <Radio label="Top" value="top" type="button" /> |
| 198 | + </RadioGroup> |
| 199 | + </FormItem> |
| 200 | + <FormItem label="用户名" :label-position="itemAlign"> |
| 201 | + <Input placeholder="请输入用户名"></Input> |
| 202 | + </FormItem> |
| 203 | + <FormItem label="密码" :label-position="itemAlign"> |
| 204 | + <Input placeholder="请输入密码"></Input> |
| 205 | + </FormItem> |
| 206 | + <FormItem label="" :label-position="itemAlign"> |
| 207 | + <Button html-type="submit">提交</Button> |
| 208 | + </FormItem> |
| 209 | + </Form> |
| 210 | + </template> |
| 211 | + </CodePreview> |
| 212 | +</ClientOnly> |
152 | 213 |
|
153 | 214 | ## API |
154 | 215 |
|
155 | 216 | ### Form Props |
156 | 217 |
|
| 218 | +<!-- prettier-ignore --> |
157 | 219 | | 参数 | 说明 | 类型 | 默认值 | |
158 | 220 | | ------------- | --------------------------------------------------------------------------- | --------------------- | ------ | |
159 | 221 | | `model` | 表单数据对象 | `Record<string, any>` | - | |
160 | 222 | | `rules` | 表单验证规则 | `FormRule[]` | - | |
161 | 223 | | `label-width` | 标签的长度,例如 `50px`。 作为 `Form` 直接子元素的 `form-item` 会继承该值。 | `string` | - | |
| 224 | +| `label-position` | 标签的位置 | `left`、`right`、`top` | `right` | |
162 | 225 |
|
163 | 226 | ### Form Events |
164 | 227 |
|
|
168 | 231 |
|
169 | 232 | ### FormItem Props |
170 | 233 |
|
| 234 | +<!-- prettier-ignore --> |
171 | 235 | | 参数 | 说明 | 类型 | 默认值 | |
172 | 236 | | ------------- | -------------------------------------------------------------------------------------- | --------- | ------ | |
173 | 237 | | `label` | 标签文本 | `string` | - | |
174 | 238 | | `required` | 是否为必填项,如不设置,则会根据校验规则确认 | `boolean` | - | |
175 | 239 | | `name` | `model` 的键名; 使用表单校验时必填 | `string` | - | |
176 | 240 | | `label-width` | 标签宽度,例如 `50px` | `string` | - | |
177 | 241 | | `error` | 表单域验证错误时的提示信息。设置该值会导致表单验证状态变为 `error`,并显示该错误信息。 | `string` | - | |
| 242 | +| `label-position` | 标签位置, *可选* | `left`、`right`、`top` | - | |
0 commit comments