1.点击事件切换
month:function(e){
var that = this
if (that.data.month === e.target.dataset.month){
return false
} else {
that.setData({
month: e.target.dataset.month
})
}
}
2.三元运算符
class="{{ today ? 'on' : 'default' }}"
src="../images/{{ bool ? 'weixuanzhong' : 'xuanzhong' }}.png"
3.截取字符串
<wxs module="util">
var sub = function(val) {
return val.substring(0, 2)
}
module.exports.sub = sub;
</wxs>
<view>{{util.sub(gatewayIeee.name)}}</view>
4.小程序判断空
if (array === undefined || array.length == 0) {
// array empty or does not exist
}
网友评论