簡體   English   中英

Vue.js:將變量連接到圖像 URL

[英]Vue.js: Concatenate variable into image URL

我是 Vue.js 的新手,並試圖創建一個 src 文件路徑包含變量的圖像。 我很難在 Vue.js 中連接。

我有這樣的圖像:

<img:src="'https://openweathermap.org/img/w/04d.png'"/>

我想連接 '04d.png' 部分,使其是動態的,並顯示從 API 調用返回的任何圖像。 如何在 url 上添加變量?

我試過這個:

<img :src="'https://openweathermap.org/img/w/+${iconCode}'"/>

我嘗試了一堆不同的單引號、雙引號、反引號等組合......但沒有任何效果。 在Vue的圖像標簽中將變量連接到字符串url的正確方法是什么?

使用反引號使其成為 JavaScript 模板字符串:

<img :src="`https://openweathermap.org/img/w/${iconCode}.png`"/>

您好,嘗試以下作為 URL 參數:

“' https://openweathermap.org/img/w?paramName= ${iconCode}'”

像這樣

<img :src="'https://openweathermap.org/img/w/'+ ${iconCode}"/>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM