我想尝试删除产品名称。当我点击+
时,按方法添加小米的产品名称。然后点击-
,结果是{{1}我认为控制台日志应该是remove: ["Iphone 4S"]
。转到jsfiddle。
remove: ["Xiaomi"]
var app = new Vue({
el: "#app",
data: {
phone: [{
id: "1",
name: 'Iphone 4S',
price: '300',
count: "0"
}, {
id: "2",
name: 'Xiaomi',
price: '200',
count: "0"
}, {
id: "3",
name: 'vivo X20',
price: '320',
count: "0"
}],
addcart: []
},
methods: {
lessClick(item) {
if (item.count > 0) {
item.count--
console.log("remove:", this.addcart.splice(item.name, 1))
}
},
addClick(item) {
item.count++
console.log("add:", this.addcart.push(item.name))
}
}
})
答案 0 :(得分:2)