簡體   English   中英

數據未在 vue.js 中的圖像標記中呈現

[英]Data not rendered in image tag in vue js

在這里,我試圖顯示 vue.js 中數據 object 的圖像。這是我的代碼

<a onclick="openModal()"><img src="{{product.productImageList[0]['name']}}"></a>

但它在dom中顯示為

<img src="{{product.productImageList[0]['name']}}">

此外,如果我將 {{product.productImageList[0]['name']}} 保留在圖像標簽之外,那么它會顯示價值

{{}}是用於顯示文本的模板。 對於屬性,而是使用v-bind和有效的 javascript 表達式。 更改為以下內容應該有效:

<img v-bind:src="product.productImageList[0]['name']">

由於參數是一個變量,請嘗試像下面這樣綁定輸入

<img :src="product.productImageList[0]['name']">

刪除插值

<img v-bind:src="product.productImageList[0]['name']">

對於 go 與

<img v-bind:src="'https ://admin.com/item_image/'+product.productImageList[0]['name']">

或者使用計算屬性

computed: {
getUrl() {
 return url=> {
  const newUrl = `https ://admin.com/item_image/${product.productImageList[0].name}`;
return newUrl;
 }
}
}

以及以下模板更改

<img v-bind:src="getUrl(product.productImageList[0].name)">

暫無
暫無

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

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