1.多状态返回
之前的笨写法
<text class="word" wx:if="{{ optionInfo.supplyScaleUnit == 1 }}">Nm³/h</text>
<text class="word" wx:if="{{ optionInfo.supplyScaleUnit == 0 }}">kg/h</text>
<text class="word" wx:if="{{ optionInfo.supplyScaleUnit == 2 }}">吨</text>
好的写法:
但是在写小程序的时候发现微信小程序的wxml不支持
<text class="card-left-tag-text" >
{{ {0: '未交班', 1: '未接班', 2: '已完成', 3: '已延期'}[items.turnoverType] }}
</text>
微信小程序支持写法:
<text class="word">{{supplyScaleList[optionInfo.supplyScaleUnit].label}}</text>
以前真的太笨了,不思考,总想着怎么快这么写
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 => {})