vue问题六:计算属性,依赖发生变化时,重新计算computed:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<el-form-item label="单价:" prop="price" > <el-input v-model="addform.price" type="number" placeholder="请输入单价" auto-complete="off" class="widc" ></el-input> </el-form-item> <el-form-item label="数量:" prop="number" > <el-input v-model="addform.number" type="number" placeholder="请输入数量" auto-complete="off" class="widc" ></el-input> </el-form-item> <el-form-item label="总金额:" prop="sum" > <div v-model="addform.countNum" class="border" ><span style="margin-left: 10%">{{countNum}}</span></div> </el-form-item>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
// 计算总金额
computed:{
countNum:function(addform){
let countNum=Number(this.addform.price) * Number(this.addform.number)
return countNum
}
},