作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试制作一个组件,但这是说我没有定义“addToCart”。我已经在同一组件中定义了它,但是我仍然遇到相同的错误吗?
Vue.component("solid-back",{
template: `
<div>
<h1>{{ title }}</h1>
<img :src="image">
<h3>Price</h3>
<p>{{price}}</p>
<ul id="deets">
<li v-for="detail in details">{{ detail }}</li>
</ul>
<button v-on:click="addToCart"
id="btn_add-to-cart">
Add to Cart
</button>
<button id="btn_buy-now">
Buy Now
</button>
</div>
`,
data() {
return {
title: "Solid Back Black Chair",
image: "./photos/chairs/solidblack.jpg",
price: "$34.00",
details: ["3 feet tall", "Oakwood", "8 pounds"],
}
},
method: {
addToCart() {
this.$emit("add-to-cart")
}
}
})
[Vue warn]: Property or method "addToCart" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option or for class-based components, by initializing the property.
最佳答案
要在Vue中定义方法,属性键为methods
。看来您的methods
属性拼写错误(单数)method
。
将其更改为methods: { ... }
应该可以工作:
methods: {
addToCart() {
this.$emit("add-to-cart")
}
}
关于vue.js - Vue.js属性或方法 “addToCart”未在实例上定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57949995/
我必须为 addToCart 方法创建代码才能将项目添加到 itemList。我在这里查看了其他 ShoppingCart 问题,但我没有看到一个会增加商品数量并检查商品名称以查看其是否在数组中的问题
我有一个表格,其中每行/项目都有一个 addtocart 按钮 $( $table ).delegate(".Addtocart", "click", function() {
我正在为一个类做一个 Java 应用程序,需要帮助解决运行该应用程序后出现的错误。 该应用程序应该允许用户将商品添加到购物车(商品名称、价格、数量)。用户描述的商品会添加到购物车数组中,添加成功后会打
我正在尝试制作一个组件,但这是说我没有定义“addToCart”。我已经在同一组件中定义了它,但是我仍然遇到相同的错误吗? Vue.component("solid-back",{ templ
我是一名优秀的程序员,十分优秀!