Created
June 5, 2017 09:56
-
-
Save boonyasukd/721db9b6c6f6f3d1e41a757101614190 to your computer and use it in GitHub Desktop.
separate validation rules out to provider()
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
<template> | |
<vee-form class="login-form"> | |
<vee-form-item> | |
<vee-input name="email" title="Email" size="large" | |
v-model="email" v-validate /> | |
</vee-form-item> | |
<vee-form-item> | |
<vee-input name="password" title="Password" type="password" size="large" | |
v-model="password" v-validate /> | |
</vee-form-item> | |
<vee-form-item> | |
<el-button size="large" type="primary" @click="validateForm()">Log-in</el-button> | |
</vee-form-item> | |
</vee-form> | |
</template> | |
<script> | |
import Debug from 'debug'; | |
const debug = Debug('Login comp:'); | |
export default { | |
$validates: true, | |
provide: { | |
rules: { | |
email: 'required|email', | |
password: 'required', | |
}, | |
}, | |
data() { | |
return { | |
email: '', | |
password: '', | |
}; | |
}, | |
methods: { | |
validateForm() { | |
this.$validator.validateAll().then(() => { | |
debug('No errors in Login form. Submitting to server...'); | |
}).catch(() => { | |
debug(`Error while validating the login form:\n${JSON.stringify(this.errors)}`); | |
}); | |
}, | |
}, | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment