[Vuejs]-V-bind:class to an object value

0👍

You shouldn’t use selectedImages[image.id] to get value and selectedImages is a object. I think should write as follows

selectedImages->image.id

if it is too complex, you should use “methods” to return value

0👍

I prefer immutable method, assigning this.selectedImages to new object:

updateSelectedImages: function (imageId) {
  /* First we check we populated selectedImages with the IDs. */
  if (Object.keys(this.selectedImages).length === 0) {
      for (var i = 0; i < this.images.length; i++) {
          this.selectedImages[this.images[i].id] = false;
      }
  }
  this.selectedImages[imageId] = !this.selectedImages[imageId];
  this.selectedImages = [...this.selectedImages] // ES6
  // this.selectedImages = JSON.parse(JSON.stringify(this.selectedImages)) // ES5
}

Leave a comment