iview/examples/routers/form.vue

48 lines
1.5 KiB
Vue
Raw Normal View History

2017-01-03 16:18:21 +08:00
<template>
2017-04-01 12:08:08 +08:00
<div style="width: 300px;">
2017-04-25 14:50:37 +08:00
<i-form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="80">
<Form-item label="爱好" prop="interest">
2017-06-02 14:23:34 +08:00
<Input v-model="formValidate.interest" number></Input>
</Form-item>
<Form-item>
2017-04-25 14:50:37 +08:00
<i-button type="primary" @click="handleSubmit('formValidate')">提交</i-button>
<i-button type="ghost" @click="handleReset('formValidate')" style="margin-left: 8px">重置</i-button>
</Form-item>
2017-04-25 14:50:37 +08:00
</i-form>
</div>
2017-01-03 16:18:21 +08:00
</template>
<script>
export default {
data () {
2017-01-03 18:13:59 +08:00
return {
2017-04-25 14:50:37 +08:00
formValidate: {
2017-06-02 14:23:34 +08:00
interest: ''
2017-01-06 11:30:01 +08:00
},
2017-04-25 14:50:37 +08:00
ruleValidate: {
interest: [
2017-06-02 14:23:34 +08:00
{
required: true,
type: 'number',
trigger: 'change'
}
2017-03-08 15:31:59 +08:00
]
2017-01-03 18:13:59 +08:00
}
}
2017-01-03 16:18:21 +08:00
},
2017-01-03 18:13:59 +08:00
methods: {
2017-04-01 12:08:08 +08:00
handleSubmit (name) {
this.$refs[name].validate((valid) => {
if (valid) {
this.$Message.success('提交成功!');
} else {
this.$Message.error('表单验证失败!');
}
})
},
handleReset (name) {
this.$refs[name].resetFields();
}
2017-01-03 18:13:59 +08:00
}
}
2017-04-01 12:08:08 +08:00
</script>