三目运算符
一般写法
// 正常判断
if (this.isSubscribe === 'T') {
this.subscriptMsg = '已订阅';
} else {
this.subscriptMsg = '订阅';
}
代码CR
// 判断内容简单,且为改变同一个变量的值
this.subscriptMsg = this.isSubscribe === 'T' ? '已订阅' : '订阅';
双元运算
一般写法
// 正常判断,没有涉及else的情况
if (this.consDefaultInfo.cons_no) {
await this.getArrearsList({ query_value: this.consDefaultInfo.cons_no });
}
代码CR
// 双元运算,内容只有一句
this.consDefaultInfo.cons_no &&
(await this.getArrearsList({ query_value: this.consDefaultInfo.cons_no }));