Code Monkey home page Code Monkey logo

Comments (2)

jainnieh avatar jainnieh commented on May 28, 2024

我已经有了解决方案, 请参考:

 // 滚动加载事件
 pullUp() {
      console.log('getComment')
      getComment(this.$route.params.id, this.page).then(({ comments }) => {
        // 因为重复的部分是有规律的, 即已经获取的所有评论commentList最后的部分可能会和新请求的comments前面几个重复.
        //所以只要遍历可能重复的部分, 直到不再遇到重复就可以停止遍历
        let commentsLen = comments.length
        for (let i = 0; i < commentsLen; i++) {
          let originSearch = this.commentList.length - 1 - i
          if (comments[i].commentId === this.commentList[originSearch].commentId) {
            const duplicate = comments.shift()
            console.log('重复: ')
            console.log(duplicate)
            i--
            commentsLen--
          } else {
            break
          }
        }
        this.commentList = [...this.commentList, ...comments]
        console.log('@@@ 合并后: ')
        // 如果this.commentList.length不是30的倍数,则说明有重复的
        console.log(this.commentList.length)
        console.log(comments.length)
        console.log(this.commentList)
        console.log(comments)
      })
    }

from vue-mmplayer.

jainnieh avatar jainnieh commented on May 28, 2024

好像可以先标记出重复, 然后截取comments. 我对js语法不太熟悉. 作者你可以看着进行优化

from vue-mmplayer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.