zoukankan      html  css  js  c++  java
  • iview 表单验证

    <!DOCTYPE html>
    <html>

    <head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" type="text/css" href="css/iview.css" />
    <script src="js/vue.min.js"></script>
    <script type="text/javascript" src="js/iview.min.js"></script>
    </head>

    <body>
    <div id="example">
    <row>
    <i-col span="6" offset="9">
    <i-form :label-width="100" ref='formItemP' :model="formItemP" :rules='ruleValidateP'>
    <form-item label="请输入旧密码" prop="oldPwd">
    <i-input placeholder="请输入旧密码" v-model="formItemP.oldPwd" name=""></i-input>
    </form-item>
    <form-item label="请输入新密码" prop="newPwd">
    <i-input placeholder="请输入新密码" v-model="formItemP.newPwd"></i-input>
    </form-item>
    <form-item label="重新输入密码" prop="repeatPwd">
    <i-input placeholder="重新输入密码" v-model="formItemP.repeatPwd"></i-input>
    </form-item>
    <form-item>
    <i-button type="primary" @click="handleSubmit('formItemP')">提 交</i-button>
    <i-button type="ghost" @click="handleReset('formItemP')" style="margin-left: 8px">重 置</i-button>
    </form-item>
    </i-form>
    </i-col>
    </row>
    </div>

    <script type="text/javascript">
    var app = new Vue({
    el: "#example",
    data: {
    formItemP: {
    oldPwd: "",
    newPwd: "",
    repeatPwd: ""
    },
    ruleValidateP: {
    oldPwd: [{
    required: true,
    message: '请输入旧密码',
    trigger: 'blur'
    }],
    newPwd: [{
    required: true,
    message: '请输入新密码',
    trigger: 'blur'
    }],
    repeatPwd: [{
    required: true,
    trigger: 'blur',
    validator: function(rule, value, callback) {
    if(value == '') {
    return callback(new Error('请再次输入密码'));
    } else if(value != app.formItemP.newPwd) {
    return callback(new Error('两次密码不一致'));
    } else {
    callback();
    }
    }
    }]
    }
    },
    methods: {
    handleSubmit(name) {
    this.$refs[name].validate((valid) => {
    if(valid) {
    this.$Message.success('成功!');
    } else {
    this.$Message.error('失败!');
    }
    })
    },
    handleReset(name) {
    this.$refs[name].resetFields();
    }
    }

    })
    </script>
    </body>

    </html>

      

     

      

  • 相关阅读:
    java笔记之连接数据库
    关于数据集合的使用
    ubuntu下安装MySql
    Android笔记之Broadcast广播机制
    InputStream
    Android笔记之Toast
    jqGrid 复选框实现单选
    layer弹出框包含页面
    input不显示边框
    UUID
  • 原文地址:https://www.cnblogs.com/lgjc/p/9220318.html
Copyright © 2011-2022 走看看