vant tab选项卡 左右滑动 且保留数据

该博客主要讨论前端页面的滚动加载实现,使用`onClick`和`onLoad`事件处理数据加载。当列表项的`products`长度为0时,启动加载状态。`onLoad`方法中,通过API获取数据并更新产品列表,同时处理分页。当达到最后一页时,设置加载状态为已完成。此外,`handleScroll`函数用于监听滚动事件,改变背景透明度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    onClick() {
      this.$nextTick(() => {
        document.documentElement.scrollTop = document.body.scrollTop = this.list[this.active].scrollTop
      })
      if (this.list[this.active].products.length > 0) return
      this.list[this.active].loading = true;
      this.onLoad()
    },
    onLoad() {
      const data = {
        newsType: this.active == 0 ? null : this.active,
        pageNum: this.list[this.active].page,
        pageSize: this.pages.size
      }
      newsManager(data).then(res => {
        res.data.list.map(item => {
          item.videoThumb = JSON.parse(item.videoThumb)
          item.newsImgs = item.newsImgs ? JSON.parse(item.newsImgs) : []
        })

        this.list[this.active].products = this.list[this.active].products.concat(res.data.list)
        if (res.data.list.length > 0) {
          this.list[this.active].page++
        }

        // 加载状态结束
        this.list[this.active].loading = false;
        // 数据全部加载完成
        
        if (this.list[this.active].page > res.data.totalPage) {
          this.list[this.active].finished = true;
        }
      })
    },
    handleScroll() {
      let s = document.documentElement.scrollTop || document.body.scrollTop
      this.list[this.active].scrollTop = s
      if (s >= 100) {
        s = 100
      } 
      this.$refs.nav.$el.style.background = `rgba(255,255,255, ${s * 0.01})`
    },

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值