Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

146
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!