Quellcode durchsuchen

Move reusable stuff to vue mixin

Bubka vor 4 Jahren
Ursprung
Commit
07df0cd5e0
3 geänderte Dateien mit 31 neuen und 15 gelöschten Zeilen
  1. 1 2
      resources/js/app.js
  2. 4 13
      resources/js/components/Footer.vue
  3. 26 0
      resources/js/mixins.js

+ 1 - 2
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,

+ 4 - 13
resources/js/components/Footer.vue

@@ -8,7 +8,7 @@
             </div>
         </div>
         <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 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>
@@ -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()
                 }
-            },
-
+            }
         }
     };
 </script>

+ 26 - 0
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' })
+        },
+    }
+
+})