Created
March 6, 2017 07:39
-
-
Save GeekGhc/c2e1ebb44f63772c0dc59b04681853bb to your computer and use it in GitHub Desktop.
concrete validations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default{ | |
data(){ | |
return{ | |
newUser: { | |
name:'', | |
email:'', | |
password:'', | |
confirm_pwd:'' | |
}, | |
} | |
}, | |
validations: { | |
newUser:{ | |
name: { | |
required, | |
minLength: minLength(4), | |
async isUnique (value) { | |
if (value === '') return true | |
const response = await fetch(`http://localhost:8000/api/unique/name/${value}`) | |
return Boolean(await response.json()) | |
} | |
}, | |
email: { | |
required, | |
email, | |
async isUnique (value) { | |
if (value === '') return true | |
const response = await fetch(`http://localhost:8000/api/unique/email/${value}`) | |
return Boolean(await response.json()) | |
} | |
}, | |
password: { | |
required, | |
minLength: minLength(6) | |
}, | |
confirm_pwd: { | |
required, | |
sameAsPassword: sameAs('password') | |
} | |
} | |
}, | |
methods:{ | |
register:function(value){ | |
value.$touch();//验证所有信息 | |
if(!value.$error){ | |
console.log("name = "+this.newUser.name) | |
this.axios.post('http://localhost:8000/api/user/register',{user:this.newUser}).then(response => { | |
console.log("data = "+response.data.status) | |
}) | |
} | |
} | |
}, | |
components:{ | |
SiteHeader | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment