利用vue2.0 的computed计算属性,去动态监听数据变化,再通过数据传递到组件
下面来看代码:
computed: {
selectFoods() {
let foods = [];
this.goods.forEach((good) => {
good.foods.forEach((food) => {
if (food.count) {
foods.push(food);
}
});
});
return foods;
}
}
-------组件传递---
<v-shopcart :select-foods="selectFoods" ></v-shopcart>
-----------组件接收----------
export default {
props: {
food: {
type: Object
}
}
}