vue一次监听对象里的多个属性(可用于多个文本框输入值后的计算求和)

data:{
	caseDetailInfo: {
		attorneyFee:"",
		attorneyCourtFee:"",
		attorneySurveyFee :"",
		attorneyOtherFee:"",
		other:[],
	}
},
watch:{
// 监听对象caseDetailInfo里的四个属性(计算总费用)
    countSum() {
      const { attorneyFee, attorneyCourtFee, attorneySurveyFee ,attorneyOtherFee} = this.caseDetailInfo;
      return {
        attorneyFee,
        attorneyCourtFee,
        attorneySurveyFee,
        attorneyOtherFee
      };
    }
},
computed:{
	countSum: {
	      deep: true,  // 深度监听
	      handler(newVal,oldVal) {
	         this.calculateSum();
	      }
	    }
},
methods: {
// 计算总费用
    calculateSum(){
      console.log(11);
   	  this.caseDetailInfo.attorneyAllFee=Number(this.caseDetailInfo.attorneyFee)+Number(this.caseDetailInfo.attorneyCourtFee)+Number(this.caseDetailInfo.attorneySurveyFee)+Number(this.caseDetailInfo.attorneyOtherFee);
    },
}

你可能感兴趣的:(vue.js,javascript,前端)