1

I load some images like this in my template:

<img
    v-if="idRobot === 7"
    src="~@/assets/img/faceTibot.png" />

But I'd like to load the asset dynamically. For example, something like this would be great:

<img
    v-if="idRobot === 7"
    :src="`~@/assets/img/${dynamicasset}.png`" />

Actually, when I do this, VueJS thinks I want to load the string "~@/assets/img/${dynamicasset}.png".

Is what I want even possible in VueJS3? Ah, BTW I searched SO and found this but suggested require solutions don't work: https://stackoverflow.com/a/47480286/1098303

Thanks in advance

djcaesar9114
  • 1,880
  • 1
  • 21
  • 41

1 Answers1

0

Have you tried this solution ?

<img :src="require(`~@/assets/img/${dynamicasset}.png`)" />