Skip to content

Instantly share code, notes, and snippets.

@GeekGhc
Created March 6, 2017 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GeekGhc/c2e1ebb44f63772c0dc59b04681853bb to your computer and use it in GitHub Desktop.
Save GeekGhc/c2e1ebb44f63772c0dc59b04681853bb to your computer and use it in GitHub Desktop.
concrete validations
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