遍历数组将对象push()到新数组里面,在vue里面一直出错

需求:遍历数组,用if判断选出符合要求的对象,然后把它push到新的数组里面

https://img1.mukewang.com/5c07761700016e6107520141.jpg

上代码:

GetAlbumList() {

        let uid = this.$route.query.Uid

    this.$http.get(url, {params: {

      '': this.userInformation

    }}).then((res) => {

      this.aList = res.data.Data.List

      for (let i = 0; i < this.aList.length; i++) {

        if (this.aList[i].Access != 0) {

          console.log(this.aList[i])

          this.albumNameList.push(this.aList[i])

        }

      }

    })

  }

  

 console.log出来的对象都是正确的,在if里面使用push就报错了,除去if条件,用push就不报错了,但是这样又租不到需求,请问这是什么原因?


不负相思意
浏览 1766回答 1
1回答

HUWWW

&nbsp; &nbsp; let uid = this.$route.query.Uid&nbsp; &nbsp; this.$http.get(url, {params: {&nbsp; &nbsp; &nbsp; '': this.userInformation&nbsp; &nbsp; }}).then((res) => {&nbsp; &nbsp; &nbsp; this.aList = res.data.Data.List;&nbsp; &nbsp; &nbsp; if (!this.albumNameList) this.albumNameList = [];&nbsp; &nbsp; &nbsp; for (let i = 0; i < this.aList.length; i++) {&nbsp; &nbsp; &nbsp; &nbsp; if (this.aList[i].Access != 0) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log(this.aList[i])&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.albumNameList.push(this.aList[i])&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; })&nbsp; }
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript