admin管理员组文章数量:1301534
I'm brand new to Vue.js and trying to create an image who's src file path contains a variable. I am having a hard time concatenating in Vue.js.
I have an image like this:
<img :src="'.png'"/>
I want to concatenate the '04d.png' part so that it is dynamic and shows whatever image ing back from the API call. How do I add a variable onto the url?
I've tried this:
<img :src="'/+${iconCode}'"/>
I've tried a bunch of different binations of single quotes, double quotes, backticks, etc... and nothing works. What is the proper way to concatenate a variable onto a string url in an image tag in Vue?
I'm brand new to Vue.js and trying to create an image who's src file path contains a variable. I am having a hard time concatenating in Vue.js.
I have an image like this:
<img :src="'https://openweathermap/img/w/04d.png'"/>
I want to concatenate the '04d.png' part so that it is dynamic and shows whatever image ing back from the API call. How do I add a variable onto the url?
I've tried this:
<img :src="'https://openweathermap/img/w/+${iconCode}'"/>
I've tried a bunch of different binations of single quotes, double quotes, backticks, etc... and nothing works. What is the proper way to concatenate a variable onto a string url in an image tag in Vue?
Share asked Sep 23, 2019 at 20:53 Nick KinlenNick Kinlen 1,4045 gold badges34 silver badges62 bronze badges 1- 1 I think you don need a '+' sign it should work without it – Loki Commented Sep 23, 2019 at 21:08
3 Answers
Reset to default 8Use backticks to make it a JavaScript template string:
<img :src="`https://openweathermap/img/w/${iconCode}.png`"/>
Like so
<img :src="'https://openweathermap/img/w/'+ ${iconCode}"/>
Hello try the following as a URL Parameter:
"'https://openweathermap/img/w?paramName=${iconCode}'"
本文标签: javascriptVuejs Concatenate variable into image URLStack Overflow
版权声明:本文标题:javascript - Vue.js: Concatenate variable into image URL - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741677886a2391991.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论