[Vuejs]-How to change the src of an image from a list of images displayed using v-for?

0👍

The problem with this code is that the URL of the image you’re intending to set ([some image link]) is not being used.

Indeed, you’re checking if BrandImageSrc (the current image URL) is non-null, then you’re setting the image URL to [some image link] regardless of the imageurl passed to changeBrandImage.

If you intend to replace the product image with a new image when a chip is clicked, you’ll need to make use of imageurl, which is being passed to changeBrandImage as a parameter. Here is how you might do it:

changeBrandImage(productCode, imageurl) { 
    var BrandImageId = productCode + "-imgProductImage";
    var BrandImage = $('#' + BrandImageId);

    if (BrandImage != null) {
         BrandImage.attr('src', imageurl);
    }
}

In this code, imageurl, which is passed as an argument, is used to change the brand image URL.

Leave a comment