vue计算总金额

var app = new Vue({
	el:'#app',
	form: {
		total_num:10,
		money:1;
		totalMoney:0,
	},
	computed: {
		sum: function() {
			if(this.form.total_num < 0) {
				return parseFloat(0).toFixed(2);
			}
			return parseFloat(this.form.total_num * this.form.money).toFixed(2);
		}
	},
	watch: {
		sum: {
			handler(val) {
				this.form.totalMoney = val
			},
			immediate:true,
			deep:true
		}
	}
})
Logo

前往低代码交流专区

更多推荐