qq_36604562
qq_36604562
2018-12-03 06:15

关于vue.js验证输入与旧密码是否一致

5
  • vue.js

如何用vue.js写一个 修改密码中 验证旧密码是否写错 ,先谢谢大佬帮忙了















提交


import waves from '@/directive/waves' // 水波纹指令 import { changePwd } from '@/api/system' export default { name: 'PwdPage', directives: { waves }, data() { var validatePass = (rule, value, callback) => { if (value === '') { callback(new Error('请输入密码!')) } else { if (this.page.confirmPassword !== '') { this.$refs.page.validateField('confirmPassword') } callback() } } var validatePass2 = (rule, value, callback) => { if (value === '') { callback(new Error('请再次输入密码!')) } else if (value !== this.page.newPassword) { callback(new Error('两次输入密码不一致!')) } else { callback() } } return { page: { oldPassword: '', newPassword: '', confirmPassword: '' }, rules: { oldPassword: [ { required: true, message: '请输入旧密码!', trigger: 'blur' }, { min: 6, max: 64, message: '长度在6-64个字符!', trigger: 'blur' } ], newPassword: [ { required: true, message: '请输入新密码!', trigger: 'blur' }, { min: 6, max: 64, message: '长度在6-64个字符!', trigger: 'blur' }, { validator: validatePass, trigger: 'blur' } ], confirmPassword: [ { required: true, message: '请输入确认密码!', trigger: 'blur' }, { validator: validatePass2, trigger: 'blur' } ] } } }, methods: { submitForm(formName) { this.$refs[formName].validate((valid) => { if (valid) { const userName = this.$store.getters.name const { oldPassword, newPassword } = this.page changePwd({ userName, oldPassword, newPassword }).then(resp => { }) } else { return false } }) } } }
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

5条回答