咏竹莉
where there is a will,there is a way

第一种省略括号:

/*方法1*/
if(a > b) console.log('a大');
else console.log('b大');

/*三元操作运算符*/
a> b ? 'a大' : 'b大'

 

第二种使用对象形式:

let orderStatus = ''
 
if (res.data.status == '1') {
    orderStatus = '待付款'
} else if (res.data.status == '2') {
    orderStatus == '待发货'
} else if (res.data.status == '3') {
    orderStatus == '已发货'
} else if (res.data.status == '4') {
    orderStatus == '待收货'
} else if (res.data.status == '5'){
    orderStatus == '已完成'}

 

可以简写为(较为实用):

let orderStatus
let map = { '1': '待付款', '2': '待发货', '3': '已发货', '4': '待收货','5':'已完成'}
orderStatus = map[res.data.status]

 

posted on 2021-07-08 15:15  咏竹莉  阅读(510)  评论(0)    收藏  举报