[Vuejs]-Vue2 – pushing string to array just replaces existing string rather than adding it

1👍

UPDATE: stupid human error

Each local data value was in a separate component. I need to emit to the parent and maintain the array there.

0👍

Your remove method is not doing anything as, unlike push, filter does not modify the array and instead returns a new one:

this.idArr = this.idArr.filter((id) => id !== show._id);

Not sure if that would break whatever this __ob__: Observer thing is doing though, if so you may need to filter it in-place using a for loop or something.

0👍

can you try this?

data() {
      return {
        idArr: [],
      }
    },
    methods: {
      updateIdArr(show) {
        if (!this.idArr.includes(show._id)) {
          // add
          this.idArr.push(show._id);
        }
        var _this = this;
        this.$nextTick(() => {
                    delete _this.idArr[_this.idArr.findIndex(x => x.id === show._id)];
        })
     
      },
    }
}

Leave a comment