order_price() {
let fee = this.orderinfo?.total_price ?? 0;
let money = this.coupon?.money ?? 0
return (Number(fee) - Number(money)).toFixed(2)
}
7***@qq.com
- 发布:2023-10-11 09:34
- 更新:2023-10-11 16:42
- 阅读:207
w***@163.com - 前端菜鸡
this.orderinfo?.total_price:这部分代码首先检查 this.orderinfo 对象是否存在,如果存在,它会尝试获取 total_price 属性的值。如果 this.orderinfo 存在且包含 total_price 属性,那么 fee 将被赋值为 total_price 的值;如果 this.orderinfo 不存在或者 total_price 属性不存在,fee 将被赋值为 undefined。
w***@163.com
?? 0:最后,使用空值合并操作符 (??) 来处理可能的 undefined 或 null 值。如果 fee 或 money 的值为 undefined 或 null,那么它们将被赋值为 0。这确保了即使 total_price 和 money 不存在或为空,fee 和 money 也将有默认值 0。
2023-10-11 16:42