【发布时间】:2020-11-23 21:35:19
【问题描述】:
我正在尝试使用这个product 数据:
data() {
return {
sitename: 'Vue.js Pet Depot',
product: {
id: 1001,
title: 'Cat Food, 251lb bag',
description: 'A 25 pound bag of <em>irresistible</em>,' +
'organic goodness for your cat.',
price: 2000,
image: require('./assets/images/product-fullsize.jpg'),
},
cart: [],
}
},
用这个方法:
methods: {
addToCart: () => {
console.log(this.product.title + ' was added to cart');
// this.cart.push(this.product.id)
}
}
这是我的模板:
<button class="default" v-on:click="addToCart">
Add to cart
</button>
得到另一个Runtime Error
v-on 处理程序中的错误:“TypeError:无法读取属性 'product' 未定义”
【问题讨论】:
标签: vue.js