Преглед изворни кода

:recycle: limiting hero load in route watcher

tags/0.9.0
J пре 4 година
родитељ
комит
cf7ebe954a
2 измењених фајлова са 14 додато и 7 уклоњено
  1. 10
    7
      vue-theme/src/pages/list.vue
  2. 4
    0
      vue-theme/src/pages/single.vue

+ 10
- 7
vue-theme/src/pages/list.vue Прегледај датотеку

@@ -130,6 +130,9 @@ export default {
130 130
                 )
131 131
             }
132 132
         },
133
+        clearHero() {
134
+            this.$store.commit('SET_HERO', { url: null, heroType: null })
135
+        },
133 136
         async checkAndSetHero(type) {
134 137
             if (!this['allPagesLoaded']) {
135 138
                 await this.$store.dispatch('getAllPages', { sortType: null, params: null })
@@ -143,14 +146,12 @@ export default {
143 146
                 page => page.slug == type + 's',
144 147
             )[0]
145 148
 
146
-            let hero = { url: null, heroType: null }
147 149
 
148 150
             // Clear the hero and bail
149
-            if(!page) return this.$store.commit('SET_HERO', hero)
151
+            if(!page) return this.clearHero()
150 152
 
151 153
             console.log('setting hero:', page)
152
-            hero.url = page.featured
153
-            hero.heroType = 'image'
154
+            let hero = { url: page.featured, heroType:'image' }
154 155
             if (
155 156
                 page.hero &&
156 157
                 JSON.parse(page.hero) &&
@@ -187,9 +188,11 @@ export default {
187 188
     },
188 189
     watch: {
189 190
         $route(to, from) {
190
-            console.log('to:', to)
191
-            console.log('from:', from)
192
-            this.checkAndSetHero(this.type)
191
+            // Only grab the hero if moving to another list page
192
+            if (to.fullPath.split('/').filter(p => p).length < 1) {
193
+                this.clearHero()
194
+                this.checkAndSetHero(this.type)
195
+            }
193 196
 
194 197
             let sort = to.path
195 198
                 .split('/')

+ 4
- 0
vue-theme/src/pages/single.vue Прегледај датотеку

@@ -159,6 +159,9 @@ export default {
159 159
         closeGallery() {
160 160
             this.activeGalleryIndex = this.activeImageID = -1
161 161
         },
162
+        clearHero() {
163
+            this.$store.commit('SET_HERO', { url: null, heroType: null })
164
+        },
162 165
         /**
163 166
          * Everytime the posts object changes
164 167
          * we use this to set a new HERO
@@ -256,6 +259,7 @@ export default {
256 259
             // Only load post data when
257 260
             //  navigating TO a single page
258 261
             if (to.fullPath.split('/').filter(p => p).length > 1) {
262
+                this.clearHero()
259 263
                 this.loadPostData()
260 264
             }
261 265
         },

Loading…
Откажи
Сачувај