From 07df0cd5e04df446a6d00884a22789fbdec6ba50 Mon Sep 17 00:00:00 2001
From: Bubka <858858+Bubka@users.noreply.github.com>
Date: Thu, 8 Oct 2020 14:48:18 +0200
Subject: [PATCH] Move reusable stuff to vue mixin
---
resources/js/app.js | 3 +--
resources/js/components/Footer.vue | 17 ++++-------------
resources/js/mixins.js | 26 ++++++++++++++++++++++++++
3 files changed, 31 insertions(+), 15 deletions(-)
create mode 100644 resources/js/mixins.js
diff --git a/resources/js/app.js b/resources/js/app.js
index f434af8f..95745d5f 100644
--- a/resources/js/app.js
+++ b/resources/js/app.js
@@ -15,8 +15,7 @@ Vue.use(Notifications)
const app = new Vue({
el: '#app',
data: {
- appSettings: window.appSettings,
- appVersion: window.appVersion
+ appSettings: window.appSettings
},
components: { App },
i18n,
diff --git a/resources/js/components/Footer.vue b/resources/js/components/Footer.vue
index b29db082..866073a9 100644
--- a/resources/js/components/Footer.vue
+++ b/resources/js/components/Footer.vue
@@ -8,7 +8,7 @@
-
2FAuth - v{{ $root.appVersion }}
+
2FAuth - v{{ appVersion }}
{{ $t('settings.settings') }} -
{{ $t('auth.sign_out') }}
@@ -30,21 +30,12 @@
},
methods: {
-
- async logout(evt) {
+ logout() {
if(confirm(this.$t('auth.confirm.logout'))) {
- await this.axios.get('api/logout')
-
- localStorage.removeItem('jwt')
- localStorage.removeItem('user')
-
- delete this.axios.defaults.headers.common['Authorization']
-
- this.$router.push({ name: 'login' })
+ this.appLogout()
}
- },
-
+ }
}
};
diff --git a/resources/js/mixins.js b/resources/js/mixins.js
new file mode 100644
index 00000000..65870795
--- /dev/null
+++ b/resources/js/mixins.js
@@ -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' })
+ },
+ }
+
+})
\ No newline at end of file