我将在app.js中进行简单的计算,只需将产品价格乘以数量即可。我希望在laravel中显示总价值,以便用户可以预览其订单。
app.js
const app = new Vue({
el: '#item',
data() {
return {
form: {
price: 0,
quantity: 0,
total: 0
}
}
},
methods: {
updatePrice(event) {
this.form.price = event.target.value;
this.form.total = this.form.price * this.form.quantity
},
updateQuantity(event) {
this.form.quantity = event.target.value;
this.form.total = this.form.price * this.form.quantity
}
}
这很好。他们在blade文件中计算了表单值。但是我怎样才能显示总价?
我想在blade文件中显示 'total
'。我该怎么访问它呢?当我使用 @{{ total }}
时,会得到以下错误提示:
app.js:36519 [Vue warn]: Property or method "total" 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.
<p>总计:@{{ form.total }}</p>
。你试过这个了吗? - acdcjuniordelimiters: ['!{', '}!'],
并像这样使用<p>Total is: !{ form.total }!</p>
,请参见更新的答案。也许您可以尝试这个来查看问题是否不同。 - acdcjunior