简单的表单验证

<template>
    <div>
        <div class="form">
            <form action="" method="get">
               <div>旧密码:<input type="password" v-model="oldPwd" @input="oldpwd" maxlength="6"></div>
               <div>新密码:<input type="password" v-model="newPwd"></div>
               <div>确认密码:<input type="password" v-model="newPwd1" @input="test"></div>
               <input type="submit" value="提交" :disabled ="disabled">
            </form>
        </div>
        
    </div>
</template>

<script>
export default {
    data(){
        return{
            oldPwd:"",
            oldPwd1:"123456",
            newPwd:"",
            newPwd1:"",
            disabled: true,
        }
    },
    methods:{
        oldpwd(){
            if(this.oldPwd == ""){
                this.$message("请填写密码");
            }else if(this.oldPwd.length == 6){
                if(this.oldPwd !== this.oldPwd1) {
                    this.$message("旧密码输入错误!");
                }
            }
        },
        test(){
            if(this.newPwd1.length == this.newPwd.length) {
                if(this.newPwd !== this.newPwd1){
                    this.$message("两次输入密码不一致,请重新输入!")
                }else if(this.newPwd == this.newPwd1 && this.oldPwd == this.oldPwd1) {
                    this.disabled = false;
                }
            }
        }
    },
}
</script>
<style scoped>
.form {
    width: 500px;
    margin: 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
}
.form div {
    margin-bottom: 10px;
}
input[type="password"] {
    height: 20px;
}
input[type="submit"]{
    width: 200px;
    height: 30px;
    margin-top: 20px;
}
form {
    width: 100%;
}
</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值