赞
踩
上代码:
- <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
- <el-form-item label="名称" prop="name">
- <el-input type="textarea" v-model="ruleForm.name"></el-input>
- </el-form-item>
- <el-form-item>
- <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
- </el-form-item>
- </el-form>
- <script>
- export default {
- data() {
- return {
- ruleForm: {
- name: ''
- },
- rules: {
- name: [
- { required: true, message: '请输入活动名称', trigger: 'blur' },
- { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
- ]
- }
- };
- },
- methods: {
- submitForm(formName) {
- this.$refs[formName].validate((valid) => { //开启校验
- if (valid) { // 如果校验通过,请求接口,允许提交表单
- alert('submit!');
- } else { //校验不通过
- return false;
- }
- });
- }
- }
- }
- </script>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。