Move reusable stuff to vue mixin

This commit is contained in:
Bubka 2020-10-08 14:48:18 +02:00
parent 27c7b9b880
commit 07df0cd5e0
3 changed files with 31 additions and 15 deletions

3
resources/js/app.js vendored
View File

@ -15,8 +15,7 @@ Vue.use(Notifications)
const app = new Vue({ const app = new Vue({
el: '#app', el: '#app',
data: { data: {
appSettings: window.appSettings, appSettings: window.appSettings
appVersion: window.appVersion
}, },
components: { App }, components: { App },
i18n, i18n,

View File

@ -8,7 +8,7 @@
</div> </div>
</div> </div>
<div v-if="$route.name === 'settings'" class="content has-text-centered is-size-6"> <div v-if="$route.name === 'settings'" class="content has-text-centered is-size-6">
<a class="has-text-grey" href="https://github.com/Bubka/2FAuth"><b>2FAuth</b> <font-awesome-icon :icon="['fab', 'github-alt']" /></a> - v{{ $root.appVersion }} <a class="has-text-grey" href="https://github.com/Bubka/2FAuth"><b>2FAuth</b> <font-awesome-icon :icon="['fab', 'github-alt']" /></a> - v{{ appVersion }}
</div> </div>
<div v-else class="content has-text-centered"> <div v-else class="content has-text-centered">
<router-link :to="{ name: 'settings' }" class="has-text-grey">{{ $t('settings.settings') }}</router-link> - <a class="has-text-grey" @click="logout">{{ $t('auth.sign_out') }}</a> <router-link :to="{ name: 'settings' }" class="has-text-grey">{{ $t('settings.settings') }}</router-link> - <a class="has-text-grey" @click="logout">{{ $t('auth.sign_out') }}</a>
@ -30,21 +30,12 @@
}, },
methods: { methods: {
logout() {
async logout(evt) {
if(confirm(this.$t('auth.confirm.logout'))) { if(confirm(this.$t('auth.confirm.logout'))) {
await this.axios.get('api/logout') this.appLogout()
localStorage.removeItem('jwt')
localStorage.removeItem('user')
delete this.axios.defaults.headers.common['Authorization']
this.$router.push({ name: 'login' })
} }
}, }
} }
}; };
</script> </script>

26
resources/js/mixins.js vendored Normal file
View File

@ -0,0 +1,26 @@
import Vue from 'vue'
Vue.mixin({
data: function () {
return {
appVersion: window.appVersion
}
},
methods: {
async appLogout(evt) {
await this.axios.get('api/logout')
localStorage.removeItem('jwt')
localStorage.removeItem('user')
delete this.axios.defaults.headers.common['Authorization']
this.$router.push({ name: 'login' })
},
}
})