소스 검색

بازنویسی صفحه بندی به جای

 async/await

 با

 Promise
hgh 1 년 전
부모
커밋
4f07759aba
1개의 변경된 파일과 18개의 추가작업 그리고 16개의 파일을 삭제
  1. 18 16
      src/components/Widgets/ContentCategory/ContentCategoryList/ContentCategoryList.vue

+ 18 - 16
src/components/Widgets/ContentCategory/ContentCategoryList/ContentCategoryList.vue

@@ -207,24 +207,26 @@ export default {
 
       return filter
     },
-    async loadMoreContents(index, done) {
+    loadMoreContents(index, done) {
       if (this.contents.loading) return
       this.contents.loading = true
-      try {
-        const { list, paginate } = await APIGateway.content.index({ ...this.filters, page: this.nextPage, per_page: this.perPage })
-        this.nextPage = paginate.current + 1
-        if (this.nextPage > paginate.num_pages) {
-          done(true) // پایان لیست
-        } else {
-          done()
-        }
-        const newList = new ContentList(list)
-        this.contents.list = [...this.contents.list, ...newList.list]
-      } catch (error) {
-        done(true) // در صورت خطا بارگذاری را متوقف کن
-      } finally {
-        this.contents.loading = false
-      }
+      APIGateway.content.index({ ...this.filters, page: this.nextPage, per_page: this.perPage })
+        .then(({ list, paginate }) => {
+          this.nextPage = paginate.current + 1
+          if (this.nextPage > paginate.num_pages) {
+            done(true) // پایان لیست
+          } else {
+            done()
+          }
+          const newList = new ContentList(list)
+          this.contents.list = [...this.contents.list, ...newList.list]
+        })
+        .catch(() => {
+          done(true) // در صورت خطا بارگذاری را متوقف کن
+        })
+        .finally(() => {
+          this.contents.loading = false
+        })
     },
     getContentCategories () {
       const filter = this.getFilterOfCategorySearch()