老师,您好,我在shopcart.vue里面已经定义list-content模块。代码如下:
<div class="list-content" ref="listContent">
<ul>
<li class="food" v-for="food in selectFoods" :key="food.id">
<span class="name">{{food.name}}</span>
<div class="price">
<span>¥{{food.price*food.count}}</span>
</div>
<div class="cartcontrol-wrapper">
<cartcontrol @add="addFood" :food="food"></cartcontrol>
</div>
</li>
</ul>
</div>
并且定义了函数:
addFood (target) {
console.log('addFood')
this.drop(target)
},
发现点击+号和-号没反应。addFood (target)没有被调用执行也没有动画出来。
我在goods.vue中,+号和-号代码如下:
<div class="foods-wrapper" ref="foodsWrapper">
<ul>
<li v-for="item in goods" :key="item.id" class="food-list" ref="foodList">
<h1 class="title">{{item.name}}</h1>
<ul>
<li @click="selectFood(food,$event)" v-for="food in item.foods" :key="food.id" class="food-item border-1px">
<div class="icon">
<img width="57" height="57" :src="food.icon">
</div>
<div class="content">
<h2 class="name">{{food.name}}</h2>
<p class="desc">{{food.description}}</p>
<div class="extra">
<span class="count">月售{{food.sellCount}}份</span><span>好评率{{food.rating}}%</span>
</div>
<div class="price">
<span class="now">¥{{food.price}}</span><span class="old" v-show="food.oldPrice">¥{{food.oldPrice}}</span>
</div>
<div class="cartcontrol-wrapper">
<cartcontrol @add="addFood" :food="food"></cartcontrol>
</div>
</div>
</li>
</ul>
</li>
</ul>
</div>
<shopcart ref="shopcart" :selectFoods="selectFoods" :deliveryPrice="seller.deliveryPrice" :minPrice="seller.minPrice"></shopcart>
在这里面调用addFood是可以正常执行的。
addFood (target) {
console.log('addFoodtest')
this._drop(target)
},
帮忙帮忙,谢谢老师。
登录后可查看更多问答,登录/注册
掌握Vue1.0到2.0再到2.5最全版本应用与迭代,打造极致流畅的WebApp
了解课程