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

75 lines
1.6 KiB
Markdown
Raw Normal View History

2020-02-05 12:14:05 +08:00
# 行内表单
一个行内表单的例子。
```html
<n-form
inline
:label-width="80"
:model="formValue"
:rules="rules"
ref="form"
>
2020-02-05 12:48:15 +08:00
<n-form-item label="姓名" path="user.name">
<n-input v-model="formValue.user.name" placeholder="输入姓名" />
2020-02-05 12:14:05 +08:00
</n-form-item>
2020-02-05 12:48:15 +08:00
<n-form-item label="年龄" path="user.age">
<n-input placeholder="输入年龄" v-model="formValue.user.age"/>
2020-02-05 12:14:05 +08:00
</n-form-item>
2020-02-05 12:48:15 +08:00
<n-form-item label="电话号码" path="phone">
<n-input placeholder="电话号码" v-model="formValue.phone"/>
2020-02-05 12:14:05 +08:00
</n-form-item>
2020-02-24 15:31:03 +08:00
<n-form-item>
2020-02-05 12:48:15 +08:00
<n-button @click="handleValidateClick">验证</n-button>
2020-02-05 12:14:05 +08:00
</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,
2020-02-05 12:48:15 +08:00
message: '请输入姓名',
2020-02-05 12:14:05 +08:00
trigger: 'blur'
},
age: {
required: true,
2020-02-05 12:48:15 +08:00
message: '请输入年龄',
2020-02-05 12:14:05 +08:00
trigger: ['input', 'blur']
}
},
phone: {
required: true,
2020-02-05 12:48:15 +08:00
message: '请输入电话号码',
2020-02-05 12:14:05 +08:00
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')
}
})
}
}
}
```