Skip to content

Instantly share code, notes, and snippets.

@visualjerk
Last active March 26, 2021 09:31
Show Gist options
  • Save visualjerk/94b441b6d5e0919f67e00339be8c876f to your computer and use it in GitHub Desktop.
Save visualjerk/94b441b6d5e0919f67e00339be8c876f to your computer and use it in GitHub Desktop.
Testing Vue 3 Components - LoginForm.vue
<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