mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-01-12 12:25:16 +08:00
75 lines
1.6 KiB
Markdown
75 lines
1.6 KiB
Markdown
|
# 行内表单
|
||
|
一个行内表单的例子。
|
||
|
```html
|
||
|
<n-form
|
||
|
inline
|
||
|
:label-width="80"
|
||
|
:model="formValue"
|
||
|
:rules="rules"
|
||
|
ref="form"
|
||
|
>
|
||
|
<n-form-item label="Name" path="user.name">
|
||
|
<n-input v-model="formValue.user.name" placeholder="Input Name" />
|
||
|
</n-form-item>
|
||
|
<n-form-item label="Age" path="user.age">
|
||
|
<n-input placeholder="Input Age" v-model="formValue.user.age"/>
|
||
|
</n-form-item>
|
||
|
<n-form-item label="Phone" path="phone">
|
||
|
<n-input placeholder="Phone Number" v-model="formValue.phone"/>
|
||
|
</n-form-item>
|
||
|
<n-form-item v-model="formValue.phone">
|
||
|
<n-button @click="handleValidateClick">Validate</n-button>
|
||
|
</n-form-item>
|
||
|
</n-form>
|
||
|
|
||
|
<pre>
|
||
|
{{ JSON.stringify(formValue, 0, 2) }}
|
||
|
</pre>
|
||
|
```
|
||
|
```js
|
||
|
export default {
|
||
|
data () {
|
||
|
return {
|
||
|
formValue: {
|
||
|
user: {
|
||
|
name: '',
|
||
|
age: ''
|
||
|
},
|
||
|
phone: ''
|
||
|
},
|
||
|
rules: {
|
||
|
user: {
|
||
|
name: {
|
||
|
required: true,
|
||
|
message: 'Please input your name',
|
||
|
trigger: 'blur'
|
||
|
},
|
||
|
age: {
|
||
|
required: true,
|
||
|
message: 'Please input your age',
|
||
|
trigger: ['input', 'blur']
|
||
|
}
|
||
|
},
|
||
|
phone: {
|
||
|
required: true,
|
||
|
message: 'Please input your number',
|
||
|
trigger: ['input']
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
methods: {
|
||
|
handleValidateClick (e) {
|
||
|
e.preventDefault()
|
||
|
this.$refs.form.validate(errors => {
|
||
|
if (!errors) {
|
||
|
this.$NMessage.success('Valid')
|
||
|
} else {
|
||
|
console.log(errors)
|
||
|
this.$NMessage.error('Invalid')
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
```
|