鍍金池/ 問答/HTML/ vue遍歷數(shù)據(jù)添加到購(gòu)物車,相同物品僅僅疊加數(shù)量的問題?

vue遍歷數(shù)據(jù)添加到購(gòu)物車,相同物品僅僅疊加數(shù)量的問題?

以下代碼是在食物列表 遍歷出食物的名字跟價(jià)格

<div class = "foods-wrapper">
      <div class="fooList" v-for="(item,index) in goods" >
        <div v-for="food in item.foods" v-show="name==item.name" class = 'food' @click ="addCart(food)" >
          <span>{{food.name}}</span>
          <span>¥{{food.price}}</span>
   
          </div>
      </div>
    </div>

以下代碼是HTML結(jié)構(gòu)里面 顯示已經(jīng)添加食物列表

<div class="order-list">
        <ul v-for = 'food in carList'>
          <li>{{food.name}}</li><span>{{carList.count}}</span>
        </ul>
       
      </div>

    </div>

method里面的 addCart的方法 感覺這里一直有問題 應(yīng)該是傳遞數(shù)據(jù)的問題 求解

addCart(event) {
       this.carList.push(this.food)
        if (!this.carList.count) {
        Vue.set(this.carList, 'count', 0)
      }
      this.carList.count++;

      
    },
回答
編輯回答
悶騷型

https://jsfiddle.net/v1un4r4s...

你說的是這個(gè)意思嗎?

2017年8月19日 12:07