我在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
}
}
Run Code Online (Sandbox Code Playgroud)
这可以.他们计算刀片文件中的表单值.但我怎么能显示总数呢?
我想total在刀片文件中显示' '.我该如何访问?当我使用时,@{{ total }}我收到此错误:
app.js:36519 [Vue warn]:属性或方法"total"未在实例上定义,但在渲染期间引用.通过初始化属性,确保此属性在数据选项或基于类的组件中是被动的.