naive-ui/demo/documentation/components/form/enUS/inline.md

75 lines
1.6 KiB
Markdown
Raw Normal View History

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"
:rules="rules"
2019-11-01 19:01:55 +08:00
ref="form"
>
<n-form-item label="Name" path="user.name">
<n-input v-model="formValue.user.name" placeholder="Input Name" />
2019-11-01 19:01:55 +08:00
</n-form-item>
<n-form-item label="Age" path="user.age">
<n-input placeholder="Input Age" v-model="formValue.user.age"/>
2019-11-01 19:01:55 +08:00
</n-form-item>
<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: {
user: {
name: '',
age: ''
},
2019-11-01 19:01:55 +08:00
phone: ''
},
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']
}
},
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')
} else {
console.log(errors)
2019-11-28 11:05:54 +08:00
this.$NMessage.error('Invalid')
}
})
2019-11-01 19:01:55 +08:00
}
}
}
```