-
-
Save Mattchewone/b1386fbe0d76be1ed18a2e5a8befcd8f to your computer and use it in GitHub Desktop.
Simple app.vue setup with user account links
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
<template> | |
<div id="app"> | |
<div id="nav"> | |
<router-link to="/">Home</router-link> | |
<router-link v-if="!user" to="/login">Login</router-link> | |
<router-link v-if="user" to="/account">Account</router-link> | |
<a v-if="user" @click.prevent="handleLogout" href="#">Logout</a> | |
</div> | |
<router-view/> | |
</div> | |
</template> | |
<script> | |
import { mapActions } from 'vuex' | |
export default { | |
name: 'app', | |
computed: { | |
user () { | |
return this.$store.state.auth.user | |
} | |
}, | |
methods: { | |
...mapActions('auth', ['logout']), | |
handleLogout () { | |
this.logout() | |
.then(_ => { | |
this.$router.push('/') | |
}) | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment