Answer the question
In order to leave comments, you need to log in
How to pass value from data to html attribute in vue?
I'm trying to do this (I think you understand the meaning of what I want to get) but it doesn't work) how is it customary to do such things?<img src="/img/{{imgName}}.jpg" alt>
Answer the question
In order to leave comments, you need to log in
Use dynamic value binding.
Collect the value itself using normal javascript expressions:
or
You can also make a computed property if imgName is a component property:
:src="`/img/${imgName}.jpg`"
:src="'/img/' + imgName + '.jpg'"
computed: {
imgSrc() {
return `/img/${this.imgName}.jpg`;
},
},
:src="imgSrc"
methods: {
imgSrc: name => `/img/${name}.jpg`,
},
:src="imgSrc(imgName)"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question