Skip to content

Instantly share code, notes, and snippets.

@teyfix
Last active June 21, 2021 19:18
Show Gist options
  • Save teyfix/1149d40bba7063d9b198e84f964dc80b to your computer and use it in GitHub Desktop.
Save teyfix/1149d40bba7063d9b198e84f964dc80b to your computer and use it in GitHub Desktop.
vuex - login component
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