parsley/app/javascript/components/App.vue

50 lines
968 B
Vue
Raw Normal View History

2018-03-29 01:57:00 -05:00
<template>
2018-03-30 14:31:09 -05:00
<div>
<app-navbar></app-navbar>
<section id="app" class="section">
<div class="container">
<router-view v-if="!hasError"></router-view>
<div v-else>
<h1>Error!</h1>
<p>{{error}}</p>
</div>
</div>
</section>
2018-03-29 01:57:00 -05:00
</div>
</template>
<script>
2018-03-30 17:08:09 -05:00
import { mapMutations, mapState } from "vuex";
2018-03-30 14:31:09 -05:00
import AppNavbar from "./AppNavbar";
2018-03-30 17:08:09 -05:00
import api from "../lib/Api";
2018-03-30 14:31:09 -05:00
2018-03-29 01:57:00 -05:00
export default {
2018-03-30 14:31:09 -05:00
computed: {
...mapState({
hasError: state => state.error !== null,
2018-03-30 17:08:09 -05:00
error: state => state.error,
authChecked: state => state.authChecked
2018-03-30 14:31:09 -05:00
})
},
2018-03-29 01:57:00 -05:00
2018-03-30 17:08:09 -05:00
methods: {
...mapMutations([
'setUser'
])
},
mounted() {
if (this.user === null && this.authChecked === false) {
this.loadResource(api.getCurrentUser(), user => {
this.setUser(user);
})
}
},
2018-03-30 14:31:09 -05:00
components: {
AppNavbar
}
2018-03-29 01:57:00 -05:00
}
</script>