【发布时间】:2021-07-23 19:06:51
【问题描述】:
我是 vue.js 的初学者。我创建了一个 Vue 组件 "cards" ,其中包含一些 Vue 组件 "card" 。我在 :src="{ card.imgSource }" 中有一个错误。我不知道我该怎么做才能解决它。请帮帮我。
Vue.component('cards' , {
props: ['cards'],
template : `
<div class="row products">
<card v-for="(card , index) in cards" :card="card" :index="index"></card>
</div>
`
});
Vue.component('card' , {
props :['card' , 'index'],
template : `
<div class="col-md-4 product">
<div class="card">
<img :src="{ card.imgSource }" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">{{ card.title }}</h5>
<p class="card-text">{{ card.body }}</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
</div>
`
});
let imgs = "img/shoe_img.jpg";
let app = new Vue({
el : '#app',
data : {
cards : [
{ title : 'Product 1' , body : "Some quick example text to build on the card title and make up the bulk of the card's content." ,imgSource : imgs },
{ title : 'Product 2' , body : "Some quick example text to build on the card title and make up the bulk of the card's content." ,imgSource: imgs},
{ title : 'Product 3' , body : "Some quick example text to build on the card title and make up the bulk of the card's content." ,imgSource: imgs}
],
alert : {
title : '',
message : '',
show : false ,
type : ''
}
},
});
【问题讨论】:
-
去掉括号
:src="card.imgSource",数据也应该是工厂,即返回对象的函数 -
我认为这是重复的问题,您可以在这里找到答案:stackoverflow.com/questions/40491506/…
标签: javascript vue.js data-binding vuejs2