2019-11-01 19:01:55 +08:00
|
|
|
# Inline Form
|
2020-02-05 12:14:05 +08:00
|
|
|
A Example of inline form.
|
2019-11-01 19:01:55 +08:00
|
|
|
```html
|
|
|
|
<n-form
|
|
|
|
inline
|
|
|
|
:label-width="80"
|
2019-11-06 13:48:05 +08:00
|
|
|
:model="formValue"
|
2019-11-11 12:44:36 +08:00
|
|
|
:rules="rules"
|
2019-11-01 19:01:55 +08:00
|
|
|
ref="form"
|
|
|
|
>
|
2019-11-11 12:44:36 +08:00
|
|
|
<n-form-item label="Name" path="user.name">
|
2019-11-02 23:09:36 +08:00
|
|
|
<n-input v-model="formValue.user.name" placeholder="Input Name" />
|
2019-11-01 19:01:55 +08:00
|
|
|
</n-form-item>
|
2019-11-11 12:44:36 +08:00
|
|
|
<n-form-item label="Age" path="user.age">
|
2019-11-02 23:09:36 +08:00
|
|
|
<n-input placeholder="Input Age" v-model="formValue.user.age"/>
|
2019-11-01 19:01:55 +08:00
|
|
|
</n-form-item>
|
2019-11-11 12:44:36 +08:00
|
|
|
<n-form-item label="Phone" path="phone">
|
2019-11-01 19:01:55 +08:00
|
|
|
<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: {
|
2019-11-02 23:09:36 +08:00
|
|
|
user: {
|
|
|
|
name: '',
|
|
|
|
age: ''
|
|
|
|
},
|
2019-11-01 19:01:55 +08:00
|
|
|
phone: ''
|
2019-11-11 12:44:36 +08:00
|
|
|
},
|
|
|
|
rules: {
|
|
|
|
user: {
|
|
|
|
name: {
|
|
|
|
required: true,
|
|
|
|
message: 'Please input your name',
|
|
|
|
trigger: 'blur'
|
|
|
|
},
|
|
|
|
age: {
|
|
|
|
required: true,
|
|
|
|
message: 'Please input your age',
|
2019-11-11 13:35:44 +08:00
|
|
|
trigger: ['input', 'blur']
|
2019-11-11 12:44:36 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
phone: {
|
|
|
|
required: true,
|
|
|
|
message: 'Please input your number',
|
|
|
|
trigger: ['input']
|
|
|
|
}
|
2019-11-01 19:01:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
handleValidateClick (e) {
|
|
|
|
e.preventDefault()
|
2019-11-28 11:05:54 +08:00
|
|
|
this.$refs.form.validate(errors => {
|
|
|
|
if (!errors) {
|
|
|
|
this.$NMessage.success('Valid')
|
2019-11-27 17:23:24 +08:00
|
|
|
} else {
|
|
|
|
console.log(errors)
|
2019-11-28 11:05:54 +08:00
|
|
|
this.$NMessage.error('Invalid')
|
2019-11-27 17:23:24 +08:00
|
|
|
}
|
|
|
|
})
|
2019-11-01 19:01:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|