Full-Stack Web Development with Vue.js and Node

(singke) #1
Building Authentication with passport.js Chapter 6

clear () {
this.$refs.form.reset()
}
}
}
</script>

Replace the contents of the script tag of Register.vue with the following code:


<script>
import axios from 'axios';
export default {
data: () => ({
e1: false,
valid: true,
fullname: '',
email: '',
password: '',
confirm_password: '',
fullnameRules: [
(v) => !!v || 'Fullname is required'
],
emailRules: [
(v) => !!v || 'E-mail is required',
(v) => /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(v)
|| 'E-mail must be valid'
],
passwordRules: [
(v) => !!v || 'Password is required'
]
}),
methods: {
async submit () {
if (this.$refs.form.validate()) {
return axios({
method: 'post',
data: {
fullname: this.fullname,
email: this.email,
password: this.password
},
url: '/users/register',
headers: {
'Content-Type': 'application/json'
}
})
.then((response) => {
this.$swal(
Free download pdf