2020-02-05 12:14:05 +08:00
|
|
|
# 标签上置
|
2019-11-06 13:48:05 +08:00
|
|
|
```html
|
2019-11-11 13:35:44 +08:00
|
|
|
<n-form
|
|
|
|
:model="model"
|
|
|
|
:rules="rules"
|
|
|
|
ref="form"
|
|
|
|
label-placement="top"
|
|
|
|
>
|
|
|
|
<n-row :gutter="24">
|
|
|
|
<n-form-item-col :span="12" label="Input" path="inputValue">
|
|
|
|
<n-input placeholder="Input" v-model="model.inputValue" />
|
|
|
|
</n-form-item-col :span="12">
|
|
|
|
<n-form-item-col :span="12" label="Textarea" path="textareaValue">
|
|
|
|
<n-input placeholder="Textarea" v-model="model.textareaValue" type="textarea"
|
|
|
|
:autosize="{
|
|
|
|
minRows: 3,
|
|
|
|
maxRows: 5
|
|
|
|
}"
|
|
|
|
/>
|
2019-11-09 00:25:06 +08:00
|
|
|
</n-form-item-col>
|
2019-11-06 13:48:05 +08:00
|
|
|
</n-row>
|
2019-11-11 13:35:44 +08:00
|
|
|
<n-row :gutter="24">
|
|
|
|
<n-form-item-col :span="12" label="Select" path="selectValue">
|
|
|
|
<n-select placeholder="Select" :options="generalOptions" v-model="model.selectValue"/>
|
2019-11-09 00:25:06 +08:00
|
|
|
</n-form-item-col>
|
2019-11-11 13:35:44 +08:00
|
|
|
<n-form-item-col :span="12" label="Multiple Select" path="multipleSelectValue">
|
|
|
|
<n-select placeholder="Select" :options="generalOptions" v-model="model.multipleSelectValue" multiple/>
|
2019-11-09 00:25:06 +08:00
|
|
|
</n-form-item-col>
|
2019-11-06 13:48:05 +08:00
|
|
|
</n-row>
|
2019-11-11 13:35:44 +08:00
|
|
|
<n-row :gutter="24">
|
|
|
|
<n-form-item-col :span="12" label="Datetime" path="datetimeValue">
|
|
|
|
<n-date-picker type="datetime" v-model="model.datetimeValue"/>
|
|
|
|
</n-form-item-col>
|
|
|
|
<n-form-item-col :span="12" label="Switch" path="switchValue">
|
|
|
|
<n-switch v-model="model.switchValue" />
|
2019-11-09 00:25:06 +08:00
|
|
|
</n-form-item-col>
|
2019-11-06 15:57:03 +08:00
|
|
|
</n-row>
|
2019-11-07 22:49:08 +08:00
|
|
|
<n-row :gutter="24">
|
2019-11-11 13:35:44 +08:00
|
|
|
<n-form-item-col :span="12" label="Checkbox Group" path="checkboxGroupValue">
|
2019-11-09 00:25:06 +08:00
|
|
|
<n-checkbox-group v-model="model.checkboxGroupValue">
|
|
|
|
<n-checkbox value="Option 1">Option 1</n-checkbox>
|
|
|
|
<n-checkbox value="Option 2">Option 2</n-checkbox>
|
|
|
|
<n-checkbox value="Option 3">Option 3</n-checkbox>
|
|
|
|
</n-checkbox-group>
|
|
|
|
</n-form-item-col>
|
2019-11-11 13:35:44 +08:00
|
|
|
<n-form-item-col :span="12" label="Radio Group" path="radioGroupValue">
|
2019-11-09 00:25:06 +08:00
|
|
|
<n-radio-group v-model="model.radioGroupValue">
|
|
|
|
<n-radio value="Radio 1">Radio 1</n-radio>
|
|
|
|
<n-radio value="Radio 2">Radio 2</n-radio>
|
|
|
|
<n-radio value="Radio 3">Radio 3</n-radio>
|
|
|
|
</n-radio-group>
|
|
|
|
</n-form-item-col>
|
2019-11-07 22:49:08 +08:00
|
|
|
</n-row>
|
|
|
|
<n-row :gutter="24">
|
2019-11-11 13:35:44 +08:00
|
|
|
<n-form-item-col :span="12" label="Radio Button Group" path="radioGroupValue">
|
2019-11-09 00:25:06 +08:00
|
|
|
<n-radio-group v-model="model.radioGroupValue">
|
|
|
|
<n-radio-button value="Radio 1">Radio 1</n-radio-button>
|
|
|
|
<n-radio-button value="Radio 2">Radio 2</n-radio-button>
|
|
|
|
<n-radio-button value="Radio 3">Radio 3</n-radio-button>
|
|
|
|
</n-radio-group>
|
|
|
|
</n-form-item-col>
|
2019-11-11 13:35:44 +08:00
|
|
|
<n-form-item-col :span="12" label="Input Number" path="inputNumberValue">
|
2019-11-09 00:25:06 +08:00
|
|
|
<n-input-number v-model="model.inputNumberValue"/>
|
|
|
|
</n-form-item-col>
|
2019-11-07 22:49:08 +08:00
|
|
|
</n-row>
|
|
|
|
<n-row :gutter="24">
|
2019-11-11 13:35:44 +08:00
|
|
|
<n-form-item-col :span="12" label="Time Picker" path="timePickerValue">
|
2019-11-09 00:25:06 +08:00
|
|
|
<n-time-picker v-model="model.timePickerValue" />
|
|
|
|
</n-form-item-col>
|
2019-11-11 13:35:44 +08:00
|
|
|
<n-form-item-col :span="12" label="Slider" path="sliderValue">
|
2019-11-09 00:25:06 +08:00
|
|
|
<n-slider v-model="model.sliderValue" :step="5"/>
|
|
|
|
</n-form-item-col>
|
2019-11-07 22:49:08 +08:00
|
|
|
</n-row>
|
2019-11-11 13:35:44 +08:00
|
|
|
<n-row :gutter="24">
|
|
|
|
<n-form-item-col :span="14" label="Transfer" path="transferValue">
|
|
|
|
<n-transfer
|
|
|
|
v-model="model.transferValue"
|
|
|
|
:options="generalOptions"
|
|
|
|
/>
|
|
|
|
</n-form-item-col>
|
|
|
|
<n-form-item-col :span="5" label="Nested Path" path="nestedValue.path1">
|
|
|
|
<n-input placeholder="Nested Path 1" v-model="model.nestedValue.path1"/>
|
|
|
|
</n-form-item-col>
|
|
|
|
<n-form-item-col :span="5" path="nestedValue.path2">
|
|
|
|
<n-select placeholder="Nested Path 2" :options="generalOptions" v-model="model.nestedValue.path2"/>
|
|
|
|
</n-form-item-col>
|
|
|
|
</n-row>
|
|
|
|
<n-row>
|
2019-11-06 13:48:05 +08:00
|
|
|
<n-col :span="24">
|
|
|
|
<div style="display: flex; justify-content: flex-end;">
|
2020-02-05 12:48:15 +08:00
|
|
|
<n-button @click="handleValidateButtonClick" round type="primary">验证</n-button>
|
2019-11-06 13:48:05 +08:00
|
|
|
</div>
|
|
|
|
</n-col>
|
|
|
|
</n-row>
|
|
|
|
</n-form>
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
{{ JSON.stringify(model, 0, 2) }}
|
|
|
|
</pre>
|
|
|
|
```
|
|
|
|
|
|
|
|
```js
|
|
|
|
export default {
|
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
model: {
|
2019-11-11 13:35:44 +08:00
|
|
|
inputValue: null,
|
|
|
|
textareaValue: null,
|
|
|
|
selectValue: null,
|
|
|
|
multipleSelectValue: null,
|
|
|
|
datetimeValue: null,
|
|
|
|
nestedValue: {
|
|
|
|
path1: null,
|
|
|
|
path2: null
|
2019-11-06 15:57:03 +08:00
|
|
|
},
|
2019-11-11 13:35:44 +08:00
|
|
|
switchValue: false,
|
2019-11-07 22:49:08 +08:00
|
|
|
checkboxGroupValue: null,
|
|
|
|
radioGroupValue: null,
|
|
|
|
radioButtonGroupValue: null,
|
|
|
|
inputNumberValue: null,
|
|
|
|
timePickerValue: null,
|
2019-11-11 13:35:44 +08:00
|
|
|
sliderValue: 0,
|
|
|
|
transferValue: null
|
2019-11-06 13:48:05 +08:00
|
|
|
},
|
|
|
|
generalOptions: [
|
|
|
|
'groode',
|
|
|
|
'veli good',
|
|
|
|
'emazing',
|
|
|
|
'lidiculous'
|
|
|
|
].map(v => ({
|
|
|
|
label: v,
|
|
|
|
value: v
|
2019-11-11 13:35:44 +08:00
|
|
|
})),
|
|
|
|
rules: {
|
|
|
|
inputValue: {
|
|
|
|
required: true,
|
|
|
|
trigger: ['blur', 'input'],
|
2020-02-05 12:48:15 +08:00
|
|
|
message: '请输入 inputValue'
|
2019-11-11 13:35:44 +08:00
|
|
|
},
|
|
|
|
textareaValue: {
|
|
|
|
required: true,
|
|
|
|
trigger: ['blur', 'input'],
|
2020-02-05 12:48:15 +08:00
|
|
|
message: '请输入 textareaValue'
|
2019-11-11 13:35:44 +08:00
|
|
|
},
|
|
|
|
selectValue: {
|
|
|
|
required: true,
|
|
|
|
trigger: ['blur', 'change'],
|
2020-02-05 12:48:15 +08:00
|
|
|
message: '请选择 selectValue'
|
2019-11-11 13:35:44 +08:00
|
|
|
},
|
|
|
|
multipleSelectValue: {
|
|
|
|
type: 'array',
|
|
|
|
required: true,
|
|
|
|
trigger: ['blur', 'change'],
|
2020-02-05 12:48:15 +08:00
|
|
|
message: '请选择 multipleSelectValue'
|
2019-11-11 13:35:44 +08:00
|
|
|
},
|
|
|
|
datetimeValue: {
|
|
|
|
type: 'number',
|
|
|
|
required: true,
|
|
|
|
trigger: ['blur', 'change'],
|
2020-02-05 12:48:15 +08:00
|
|
|
message: '请输入 datetimeValue'
|
2019-11-11 13:35:44 +08:00
|
|
|
},
|
|
|
|
nestedValue: {
|
|
|
|
path1: {
|
|
|
|
required: true,
|
|
|
|
trigger: ['blur', 'input'],
|
2020-02-05 12:48:15 +08:00
|
|
|
message: '请输入 nestedValue.path1'
|
2019-11-11 13:35:44 +08:00
|
|
|
},
|
|
|
|
path2: {
|
|
|
|
required: true,
|
|
|
|
trigger: ['blur', 'change'],
|
2020-02-05 12:48:15 +08:00
|
|
|
message: '请输入 nestedValue.path2'
|
2019-11-11 13:35:44 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
checkboxGroupValue: {
|
|
|
|
type: 'array',
|
|
|
|
required: true,
|
|
|
|
trigger: 'change',
|
2020-02-05 12:48:15 +08:00
|
|
|
message: '请选择 checkboxGroupValue'
|
2019-11-11 13:35:44 +08:00
|
|
|
},
|
|
|
|
radioGroupValue: {
|
|
|
|
required: true,
|
|
|
|
trigger: 'change',
|
2020-02-05 12:48:15 +08:00
|
|
|
message: '请选择 radioGroupValue'
|
2019-11-11 13:35:44 +08:00
|
|
|
},
|
|
|
|
radioButtonGroupValue: {
|
|
|
|
required: true,
|
|
|
|
trigger: 'change',
|
2020-02-05 12:48:15 +08:00
|
|
|
message: '请选择 radioButtonGroupValue'
|
2019-11-11 13:35:44 +08:00
|
|
|
},
|
|
|
|
inputNumberValue: {
|
|
|
|
type: 'number',
|
|
|
|
required: true,
|
|
|
|
trigger: ['blur', 'change'],
|
2020-02-05 12:48:15 +08:00
|
|
|
message: '请输入 inputNumberValue'
|
2019-11-11 13:35:44 +08:00
|
|
|
},
|
|
|
|
timePickerValue: {
|
|
|
|
type: 'number',
|
|
|
|
required: true,
|
|
|
|
trigger: ['blur', 'change'],
|
2020-02-05 12:48:15 +08:00
|
|
|
message: '请输入 timePickerValue'
|
2019-11-11 13:35:44 +08:00
|
|
|
},
|
|
|
|
sliderValue: 0,
|
|
|
|
transferValue: {
|
|
|
|
type: 'array',
|
|
|
|
required: true,
|
|
|
|
trigger: 'change',
|
2020-02-05 12:48:15 +08:00
|
|
|
message: '请输入 transferValue'
|
2019-11-11 13:35:44 +08:00
|
|
|
}
|
|
|
|
}
|
2019-11-06 13:48:05 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
handleValidateButtonClick (e) {
|
|
|
|
e.preventDefault()
|
2019-11-28 11:05:54 +08:00
|
|
|
this.$refs.form.validate(errors => {
|
|
|
|
if (!errors) {
|
2020-02-05 12:48:15 +08:00
|
|
|
this.$NMessage.success('验证成功')
|
2019-11-27 17:23:24 +08:00
|
|
|
} else {
|
2019-11-28 11:05:54 +08:00
|
|
|
console.log(errors)
|
2020-02-05 12:48:15 +08:00
|
|
|
this.$NMessage.error('验证失败')
|
2019-11-27 17:23:24 +08:00
|
|
|
}
|
|
|
|
})
|
2019-11-06 13:48:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|