Last active
March 26, 2021 09:31
-
-
Save visualjerk/94b441b6d5e0919f67e00339be8c876f to your computer and use it in GitHub Desktop.
Testing Vue 3 Components - LoginForm.vue
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
<script> | |
export default { | |
name: 'LoginForm', | |
emits: ['submit'], | |
data() { | |
return { | |
formData: { | |
username: '', | |
password: '', | |
}, | |
} | |
}, | |
methods: { | |
handleSubmit() { | |
if (this.formData.username !== '' && this.formData.password !== '') { | |
this.$emit('submit', this.formData) | |
} | |
}, | |
}, | |
} | |
</script> | |
<template> | |
<form @submit.capture.prevent.stop="handleSubmit"> | |
<label> | |
Username | |
<input name="username" v-model="formData.username" /> | |
</label> | |
<label> | |
Password | |
<input name="password" v-model="formData.password" /> | |
</label> | |
<button type="submit">Login</button> | |
</form> | |
</template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment