Browse Source

商品列表页:记录滚动位置

panyong 2 years ago
parent
commit
8b7a9d1d4f

+ 2 - 1
htmldev/cps/src/views/category/detail/api/api.js

@@ -11,5 +11,6 @@ export const apiGoodsDetail = (source, goodsId) => request({
   params: {
     source: source,
     goods_id: goodsId
-  }
+  },
+  showLoading: true
 })

+ 10 - 4
htmldev/cps/src/views/category/index/index.vue

@@ -106,18 +106,23 @@ export default {
       ], // 商家列表
       businessValue: 'jd',
       catId: '',
-      cateList: [] // 分类列表
+      cateList: [], // 分类列表
+      numPositionY: 0 // BS纵轴坐标
     }
   },
   activated () {
     if (!this.$route.meta.isUseCache) {
       this.businessValue = this.sourceList[0].value
       this.catId = ''
+      this.numPositionY = 0
       this.fetchCateList()
     } else {
-      if (this.$refs.myMain && this.$refs.myMain.scroll) {
-        this.$refs.myMain.scroll.refresh()
-      }
+      this.$nextTick(() => {
+        if (this.$refs.myMain.scroll) {
+          this.$refs.myMain.scroll.refresh()
+          this.$refs.myMain.scroll.scrollTo(0, this.numPositionY)
+        }
+      })
     }
     setTimeout(() => {
       this.$refs.fbtBusinessList.resize()
@@ -157,6 +162,7 @@ export default {
     if (['CategoryDetail'].findIndex(item => item === to.name) > -1) {
       from.meta.isUseCache = true
     }
+    this.numPositionY = this.$refs.myMain.scroll ? this.$refs.myMain.scroll.y : 0
     next()
   }
 }