Skip to content

Instantly share code, notes, and snippets.

@Mattchewone
Created June 15, 2018 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mattchewone/b1386fbe0d76be1ed18a2e5a8befcd8f to your computer and use it in GitHub Desktop.
Save Mattchewone/b1386fbe0d76be1ed18a2e5a8befcd8f to your computer and use it in GitHub Desktop.
Simple app.vue setup with user account links
<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