瀏覽代碼

:recycle: fixing single route watch

tags/0.9.0
J 4 年之前
父節點
當前提交
69608452d7
共有 2 個檔案被更改,包括 12 行新增13 行删除
  1. 8
    10
      vue-theme/src/pages/list.vue
  2. 4
    3
      vue-theme/src/pages/single.vue

+ 8
- 10
vue-theme/src/pages/list.vue 查看文件

108
             if(!this.type) throw `post type: ${this.type} not found...`
108
             if(!this.type) throw `post type: ${this.type} not found...`
109
 
109
 
110
             // Set some default dispatch paramters
110
             // Set some default dispatch paramters
111
-            let dispatchAction = 'More'
111
+            let dispatchType = 'More'
112
             let params = { limit: this.perPage, page: this.page }
112
             let params = { limit: this.perPage, page: this.page }
113
             
113
             
114
             // For episodes, or material sort we grab EVERYTHING
114
             // For episodes, or material sort we grab EVERYTHING
115
             const getAllClause = this.type == 'episode' || this.type == 'artist' && this.sortBy == sortTypes.material
115
             const getAllClause = this.type == 'episode' || this.type == 'artist' && this.sortBy == sortTypes.material
116
             if(getAllClause) {
116
             if(getAllClause) {
117
-                dispatchAction = 'All'
117
+                // dispatchType = 'All'
118
                 params.limit = -1
118
                 params.limit = -1
119
             }
119
             }
120
 
120
 
121
             let res = []
121
             let res = []
122
             // We always grab all pages on hero init so no need to do it here
122
             // We always grab all pages on hero init so no need to do it here
123
             if(this.pType && this.keepFetching && this.type != 'page') {
123
             if(this.pType && this.keepFetching && this.type != 'page') {
124
-                res = await this.$store.dispatch(`get${dispatchAction}${this.pType}`, { sortType: this.sortBy, params })
124
+                res = await this.$store.dispatch(
125
+                    `get${dispatchType}${this.pType}`,
126
+                    { sortType: this.sortBy, params }
127
+                )
125
             }
128
             }
126
 
129
 
127
             // Stop trying to load more posts
130
             // Stop trying to load more posts
203
             // Ignore types with presorts so the sortBy watcher can handle them
206
             // Ignore types with presorts so the sortBy watcher can handle them
204
             const ignore = ['event', 'exhibition', 'artist']
207
             const ignore = ['event', 'exhibition', 'artist']
205
             if(ignore.includes(newType)) return
208
             if(ignore.includes(newType)) return
206
-            
207
             this.clearAndInitPostList('type change')
209
             this.clearAndInitPostList('type change')
208
         },
210
         },
209
         sortBy(newSort) {
211
         sortBy(newSort) {
210
-            if(Object.values(sortTypes).includes(newSort)) {
211
-                this.clearAndInitPostList('sort change')
212
-            }
212
+            if(!Object.values(sortTypes).includes(newSort)) return
213
+            this.clearAndInitPostList('sort change')
213
         }
214
         }
214
     },
215
     },
215
     mounted() {
216
     mounted() {
216
         // This only fires navigating from a non-list page > list page
217
         // This only fires navigating from a non-list page > list page
217
-        console.log(this.$route)
218
-        console.log(this.type)
219
-        console.log(this.sortBy)
220
         this.clearAndInitPostList('mounted')
218
         this.clearAndInitPostList('mounted')
221
     },
219
     },
222
     beforeDestroy() {
220
     beforeDestroy() {

+ 4
- 3
vue-theme/src/pages/single.vue 查看文件

199
                 console.warn('Could not find single post in store; Fetching everything...')
199
                 console.warn('Could not find single post in store; Fetching everything...')
200
                 const res = await this.$store.dispatch(
200
                 const res = await this.$store.dispatch(
201
                     `getAll${convertTitleCase(this.type)}s`,
201
                     `getAll${convertTitleCase(this.type)}s`,
202
-                    { sortType: null, params: null}
202
+                    { sortType: null, params: null }
203
                 )
203
                 )
204
                 singlePostData = res.filter(
204
                 singlePostData = res.filter(
205
                     post => post.slug == this.$route.params.slug,
205
                     post => post.slug == this.$route.params.slug,
223
     },
223
     },
224
     watch: {
224
     watch: {
225
         // This fires navigating to and away
225
         // This fires navigating to and away
226
-        $route(to, from) {
226
+        $route(to) {
227
             // Only load post data when navigating TO a single page
227
             // Only load post data when navigating TO a single page
228
             const path = to.fullPath.split('/').filter(p => p)
228
             const path = to.fullPath.split('/').filter(p => p)
229
-            if (path.length < 2 || !postTypes.includes(to.params.type)) return
229
+            console.log('single to :', to)
230
+            if (path.length < 2 || !postTypes.includes(to.params.type) || !to.params.sortBy) return
230
             this._clearHero(this.$store)
231
             this._clearHero(this.$store)
231
             this.loadPostData()
232
             this.loadPostData()
232
         },
233
         },

Loading…
取消
儲存