Преглед на файлове

:recycle: trying intersection on load and on route change

tags/0.9.0
J преди 4 години
родител
ревизия
124ef21f1f
променени са 1 файла, в които са добавени 13 реда и са изтрити 9 реда
  1. 13
    9
      vue-theme/src/pages/list.vue

+ 13
- 9
vue-theme/src/pages/list.vue Целия файл

44
     data() {
44
     data() {
45
         return {
45
         return {
46
             page: 1,
46
             page: 1,
47
-            perPage: 10
47
+            perPage: 9
48
         }
48
         }
49
     },
49
     },
50
     computed: {
50
     computed: {
169
                 location.href = hashtag
169
                 location.href = hashtag
170
             }, TIMEOUT)
170
             }, TIMEOUT)
171
         },
171
         },
172
+        setIntersectionLoader() {
173
+            window.removeEventListener("load", e => {}, false)
174
+            window.addEventListener("load", e => {
175
+                const footerEl = document.querySelector(".footer-wrapper footer")
176
+                const observer = new IntersectionObserver(this.loadMorePosts, {
177
+                    rootMargin: "0px 0px 20px 0px",
178
+                })
179
+                observer.observe(footerEl)
180
+            }, false)
181
+        }
172
     },
182
     },
173
     watch: {
183
     watch: {
174
         posts() {
184
         posts() {
189
             if (!this[`all${type}Loaded`] || sort) this.getPosts(true)
199
             if (!this[`all${type}Loaded`] || sort) this.getPosts(true)
190
 
200
 
191
             // Add the infinite scroll load
201
             // Add the infinite scroll load
192
-            window.removeEventListener("load", e => {}, false)
193
-            window.addEventListener("load", e => {
194
-                const footerEl = document.querySelector(".footer-wrapper footer")
195
-                const observer = new IntersectionObserver(this.loadMorePosts, {
196
-                    rootMargin: "0px 0px -20px 0px",
197
-                })
198
-                observer.observe(footerEl)
199
-            }, false)
202
+            this.setIntersectionLoader()
200
         },
203
         },
201
     },
204
     },
202
     mounted() {
205
     mounted() {
203
         if (this.$route.hash) {
206
         if (this.$route.hash) {
204
             setTimeout(() => this.scrollTo(this.$route.hash), TIMEOUT)
207
             setTimeout(() => this.scrollTo(this.$route.hash), TIMEOUT)
205
         }
208
         }
209
+        this.setIntersectionLoader()
206
     },
210
     },
207
     created() {
211
     created() {
208
         let type = convertTitleCase(this.type) + 's'
212
         let type = convertTitleCase(this.type) + 's'

Loading…
Отказ
Запис