1.form表单写法 

<template>
  <div style="height:100%;width:100%;position:relative">

    <el-dialog title="编辑" :visible.sync="dialogVisible" width='15%' :close-on-click-modal='false'>
      <el-form :model="form" :rules="rules" ref="ruleForm">
        <el-form-item label="账号" :label-width="formLabelWidth" prop="userCode" v-show="addOrEdit">
          <el-input :readonly="true" v-model="form.userCode" autocomplete="off"></el-input>
        </el-form-item>
        <!-- <el-form-item label="密码" :label-width="formLabelWidth" prop="userPwd" v-show="addOrEdit">
          <el-input v-model="form.userPwd" autocomplete="off"></el-input>
        </el-form-item> -->
        <el-form-item label="姓名" :label-width="formLabelWidth" prop="userName">
          <el-input v-model="form.userName" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="手机号" :label-width="formLabelWidth" prop="phoneNumber">
          <el-input v-model="form.phoneNumber" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="微信号" :label-width="formLabelWidth" prop="wechatCode">
          <el-input v-model="form.wechatCode" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="邮箱" :label-width="formLabelWidth" prop="email">
          <el-input v-model="form.email" autocomplete="off"></el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="append">取 消</el-button>
        <el-button type="primary" @click="addOk('ruleForm') ">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

2.rules的校验写法

private rules: any = {
    userCode: [{ required: true, message: '请填写账号', trigger: 'blur' }],
    userName: [{ required: true, message: '请填写姓名', trigger: 'blur' }],
    phoneNumber: [
      { required: true, message: '请填写手机号', trigger: 'blur' },
      { validator: this.validatePhone, message: '请填写11位手机号', trigger: 'blur' }
    ],
    email: [
      { required: true, message: '请填写邮箱号', trigger: 'blur' },
      { validator: this.validateEmail, message: '请填写正确的邮箱号', trigger: 'blur' }
    ],
    wechatCode: [{ required: true, message: '请填写微信号', trigger: 'blur' }]
    // userPwd: [{ required: true, message: '请填写登录密码', trigger: 'blur' }]
    
  }
private validatePhone() {
    if (!/^1(3|4|5|6|7|8)\d{9}$/.test(this.form.phoneNumber)) {
      return false
    } else {
      return true
    }
  }
  private validateEmail() {
    if (!/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/.test(this.form.email)) {
      return false
    } else {
      return true
    }
  }
06-01 05:35