【Vue】如何巧妙使用computed

前言:watch是个很实用的属性。不但可以用来监听form标签值的变化,还可以用来监听对象属性的变化。

 

一、案例一





test




是否已经全选
{{item.name}}

运行结果

 

二、案例二





test





商品 单价 数量 金额
{{item.name}} ¥{{item.price}} ¥{{item.price*item.num}}
总金额为¥{{ totalPrice }}

运行结果

【Vue】如何巧妙使用computed_第1张图片

 

三、将案例一跟案例二合并





test





全选 商品 单价 数量 金额
{{item.name}} ¥{{item.price}} ¥{{item.price*item.num}}
总金额为¥{{ totalPrice }}

运行结果

【Vue】如何巧妙使用computed_第2张图片

你可能感兴趣的:(Vue)