[Vuejs]-Image not rendering on page the way I would like it to using Vue

0👍

It seems you’re trying to lookup the image resource that corresponds to the country name in the data.country string. To do that, you could create a lookup table/object (1️⃣), and then reference it when creating google.maps.Marker (2️⃣):

import canada from "@/assets/country/canada.png"
import england from "@/assets/country/england.png"
import usa from "@/assets/country/usa.png"
import belgium from "@/assets/country/belgium.png"

// 1️⃣
const flags = {
  canada,
  england,
  usa,
  belgium
}

if (data.geolocation) {
  let countryMarker = data.country

  let marker = new google.maps.Marker({
    //...
    icon: flags[countryMarker] // 2️⃣
  })
}

Leave a comment