简体   繁体   English

数据未在 vue.js 中的图像标记中呈现

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

Here I am trying to show image from data object in vue.js. Here is my code在这里,我试图显示 vue.js 中数据 object 的图像。这是我的代码

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

But it shows in dom like但它在dom中显示为

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

Besides if I keep {{product.productImageList[0]['name']}} outside image tag then it shows value此外,如果我将 {{product.productImageList[0]['name']}} 保留在图像标签之外,那么它会显示价值

{{}} is a template for displaying text. {{}}是用于显示文本的模板。 For attribute, instead you use v-bind with a valid javascript expression.对于属性,而是使用v-bind和有效的 javascript 表达式。 Change to the following should work:更改为以下内容应该有效:

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

Since the argument is a variable try binding the input like below由于参数是一个变量,请尝试像下面这样绑定输入

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

Remove the interpolation删除插值

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

For concatenation either go with对于 go 与

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

Or use computed property或者使用计算属性

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

along with below template change以及以下模板更改

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM