forked from tusen-ai/naive-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(form): add show-label demo (tusen-ai#858)
- Loading branch information
kev1nzh
committed
Aug 14, 2021
1 parent
69bc5d0
commit af0b103
Showing
4 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Show/hide Label | ||
|
||
`show-label`: When the value is `false`, the `label` element and placeholder for `n-form-item` will be hidden. | ||
|
||
`n-form-item` will use the `show-label` of the enclosing `n-form` if it is not set, or default to `true` if neither is set. | ||
|
||
```html | ||
<div :style="switchStyle"> | ||
<label>n-form:</label> | ||
<n-switch v-model:value="formShowLabel" /> | ||
</div> | ||
<div :style="switchStyle"> | ||
<label>n-form-item:</label> | ||
<n-switch v-model:value="formItemShowLabel" /> | ||
</div> | ||
|
||
<n-form :model="formValue" ref="formRef" :show-label="formShowLabel"> | ||
<n-form-item label="Name" path="user.name" :show-label="formItemShowLabel"> | ||
<n-input v-model:value="formValue.user.name" placeholder="Input Name" /> | ||
</n-form-item> | ||
<n-form-item label="Age" path="user.age"> | ||
<n-input placeholder="Input Age" v-model:value="formValue.user.age" /> | ||
</n-form-item> | ||
<n-form-item label="Phone" path="user.phone"> | ||
<n-input placeholder="Input Phone" v-model:value="formValue.phone" /> | ||
</n-form-item> | ||
</n-form> | ||
``` | ||
|
||
```js | ||
import { defineComponent, ref } from 'vue' | ||
|
||
export default defineComponent({ | ||
setup () { | ||
const formRef = ref(null) | ||
const formShowLabel = ref(true) | ||
const formItemShowLabel = ref(true) | ||
return { | ||
formRef, | ||
formValue: ref({ | ||
user: { | ||
name: '', | ||
age: '' | ||
}, | ||
phone: '' | ||
}), | ||
formShowLabel, | ||
formItemShowLabel, | ||
switchStyle: { | ||
marginBottom: '12px' | ||
} | ||
} | ||
} | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# 显示/隐藏标签 | ||
|
||
`show-label`: 当值为 `false` 时,会隐藏 `n-form-item` 的 `label` 元素和占位。 | ||
|
||
`n-form-item` 若未被设定,则会使用外层 `n-form` 的 `show-label`, 若都未被设定,则默认为 `true`。 | ||
|
||
```html | ||
<div :style="switchStyle"> | ||
<label>n-form:</label> | ||
<n-switch v-model:value="formShowLabel" /> | ||
</div> | ||
<div :style="switchStyle"> | ||
<label>n-form-item:</label> | ||
<n-switch v-model:value="formItemShowLabel" /> | ||
</div> | ||
|
||
<n-form :model="formValue" ref="formRef" :show-label="formShowLabel"> | ||
<n-form-item label="姓名" path="user.name" :show-label="formItemShowLabel"> | ||
<n-input v-model:value="formValue.user.name" placeholder="输入姓名" /> | ||
</n-form-item> | ||
<n-form-item label="年龄" path="user.age"> | ||
<n-input placeholder="输入年龄" v-model:value="formValue.user.age" /> | ||
</n-form-item> | ||
<n-form-item label="电话号码" path="user.phone"> | ||
<n-input placeholder="电话号码" v-model:value="formValue.phone" /> | ||
</n-form-item> | ||
</n-form> | ||
``` | ||
|
||
```js | ||
import { defineComponent, ref } from 'vue' | ||
|
||
export default defineComponent({ | ||
setup () { | ||
const formRef = ref(null) | ||
const formShowLabel = ref(true) | ||
const formItemShowLabel = ref(true) | ||
return { | ||
formRef, | ||
formValue: ref({ | ||
user: { | ||
name: '', | ||
age: '' | ||
}, | ||
phone: '' | ||
}), | ||
formShowLabel, | ||
formItemShowLabel, | ||
switchStyle: { | ||
marginBottom: '12px' | ||
} | ||
} | ||
} | ||
}) | ||
``` |