新闻页上一篇下一篇

一开始没想出来纠结好久,后来突然开窍了,进入详情页就判断下,列表判断当前的位置 前面的就是上一个 后面的就是下一个,判断当前页的索引位置 是不是第一或者最后个【简单手写】

// 当前页
    async newsContent() {
      const all = this.xw;
      const res = await news_content({ id: this.id });
      const { title, id } = res.data.data;
      this.title = res.data.data;
      this.title1 = title;
      let index = all.findIndex((value) => value.id == id); //索引
      console.log(222, index);
      const allLen = all.length - 1;
      if (index == 0) {
        // 没有上一页
        this.title1 = "没有上一页";
        // 下一篇
        this.next1 = all[index + 1];
        this.title2 = this.next1.title;
      } else if (index == allLen) {
        // 没有下一页
        this.title2 = "没有下一页";
        // 上一篇
        this.prev1 = all[index - 1];
        this.title1 = this.prev1.title;
      } else {
        // 上一篇
        this.prev1 = all[index - 1];
        this.title1 = this.prev1.title;
        // 下一篇
        this.next1 = all[index + 1];
        this.title2 = this.next1.title;
      }
    },
 // 新闻列表
    async index() {
      const data = await index({ page: this.page });
      // console.log("index", data);
      this.total = data.data.data;
      this.first = data.data.data.first;
      this.xw = data.data.data.list;
      this.newsContent(); //当前页
    },

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值