Last active
June 21, 2021 19:18
-
-
Save teyfix/1149d40bba7063d9b198e84f964dc80b to your computer and use it in GitHub Desktop.
vuex - login component
This file contains hidden or 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
Vuex.component('app-login', { | |
template: ` | |
<section> | |
<header> | |
<h1>Giriş yap</h1> | |
</header> | |
<main v-if="user"> | |
<p>{{ user.username }} olarak giriş yapıldı</p> | |
</main> | |
<main v-else> | |
<p v-if="error">Giriş yapılamadı</p> | |
<form @submit="submit"> | |
<fieldset> | |
<legend>Giriş formu</legend> | |
<label for="username">Kullanıcı adı</label> | |
<input type="text" v-model="username" /> | |
<label for="password">Şifre</label> | |
<input type="password" v-model="password" /> | |
</fieldset> | |
</form> | |
</main> | |
</section> | |
`, | |
data: { | |
error: false, | |
username: '', | |
password: '', | |
}, | |
computed: mapState(['user']), | |
methods: { | |
submit($event) { | |
if ($event) { | |
$event.preventDefault(); | |
} | |
this.$store | |
.dispatch('login', { | |
username: this.username, | |
password: this.password, | |
}) | |
.catch(() => (this.error = true)); | |
}, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment