前端只进行计算,不涉及后台逻辑
前端代码:
在需要计算的地方使用@change事件
定义三个变量:
temp: {
price: '',
number: '',
money: ''
}
方法进行计算:
// 计算总额
calculation() {
console.log('方法执行' + '1111111111111111')
// 单价
const price = this.temp.price
console.log('单价是' + price)
// 数量
const num = this.temp.number
console.log('数量是' + num)
// 金额
const money = num * price
console.log('金额是' + money)
this.temp.money = money
}
效果图:
