一些好的写法

 1.多状态返回

之前的笨写法

Nm³/h
kg/h

 好的写法:

但是在写小程序的时候发现微信小程序的wxml不支持


  {{ {0: '未交班', 1: '未接班', 2: '已完成', 3: '已延期'}[items.turnoverType] }}

微信小程序支持写法:

{{supplyScaleList[optionInfo.supplyScaleUnit].label}}

 以前真的太笨了,不思考,总想着怎么快这么写

 2.年月拼接,pre,cur,next

let date = new Date();
      let year = date.getUTCFullYear()
      let month = date.getUTCMonth() + 1
      let pre = '';
      let cur = '';
      let next = '';
      cur = year + '-' + (month < 9 ? ('0' + month) : month)
      pre = month === 1 ? ((year - 1) + '-12') : (year + '-' + (month - 1 < 9 ? ('0' + (month - 1)) : month - 1))
      next = month === 12 ? ((year + 1) + '-01') : (year + '-' + (month + 1 > 9 ? ('0' + (month + 1)) : month + 1))
      return schedule({ dutyDate: [pre, cur, next].join(',') }).then(res => {})

你可能感兴趣的:(前端,javascript)