Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

143
Vistas
Why does binding a variable to the src parameter in the img tag not work in vuejs?

I have a Vuejs component containing an img tag. I can render the image with no problem if I hardcode the src like this.

<template>
    <div>
        <!-- <img class="rotate logo" alt="Vue logo" src="@/assets/abstractwave.png"/> -->
    </div>
</template>

<script>
export default {
    name: "RotatingImage",
    props: {
        filename: String
    },

}
</script>

I cannot render the image if I insert bind the src as a prop. As follows... Why is this? What must I change in order to render the image using a prop?

<template>
    <div>
        <img class = "rotate" alt="Vue logo" :src="`@/assets/${filename}`" />
    </div>
</template>

<script>
export default {
    name: "RotatingImage",
    props: {
        filename: String
    },

}
</script>

Upon inspection in the browser, I see that the src path is correct, yet the image does not show.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can make computed property:

computed: {
  getImgUrl() { 
     return require(`@/assets/${this.filename}`);
  }
}

Then in template bind it:

<img class = "rotate" alt="Vue logo" :src="getImgUrl" />
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda