1. 程式人生 > >微信小程序開發之三元運算符代替wx.if/wx.else

微信小程序開發之三元運算符代替wx.if/wx.else

load == 成功 圖片 運算符 spa asp photos 微信小程序

直接上代碼

實現功能為:當fbphotoFirst為空時,src路徑為“pic/信息反饋1-1_14.png“,並且點擊事件uploadfbphotoFirst有效,否則為路徑fbphotoFirst,此時點擊事件uploadfbphotoFirst無效,uploadfbphotoFirst為上傳圖片的方法,即上傳圖片成功後不支持修改

<image class="uploadimageclass"
bindtap="{{fbphotoFirst==‘‘?‘uploadfbphotoFirst‘:‘‘}}" mode="aspectFit" src="{{fbphotoFirst==‘‘?‘pic/信息反饋1-1_14.png‘:fbphotoFirst}

}"></image>
<image class="uploadimageclass"
bindtap="uploadfbphotoSecend" mode="aspectFit" src="{{fbphotoFirst==‘‘?‘pic/信息反饋1-1_14.png‘:fbphotoSecend}}"></image>
<image class="uploadimageclass"
bindtap="uploadfbphotothird" mode="aspectFit" src="{{fbphotoFirst==‘‘?‘pic/信息反饋1-1_14.png‘:fbphotothird}}"></image>

等效於以下代碼
<!--<view wx:if="{{fbphotoFirst==‘‘}}">
<image class="uploadimageclass" bindTap="uploadfbphotoFirst" src="../../../image/信息反饋/信息反饋1-1_14.png"></image></view>
<view wx:else> <image class="uploadimageclass" bindTap="uploadfbphotoFirst" src="{{fbphotoFirst}}"></image></view>

<view wx:if="{{fbphotoFirst==‘‘}}">
<image class="uploadimageclass" bindTap="uploadfbphotoSecend" src="../../../image/信息反饋/信息反饋1-1_14.png"></image></view>
<view wx:else> <image class="uploadimageclass" bindTap="uploadfbphotoSecend" src="{{fbphotoSecend}}"></image></view>

<view wx:if="{{fbphotoFirst==‘‘}}">
<image class="uploadimageclass" bindTap="uploadfbphotothird" src="../../../image/信息反饋/信息反饋1-1_14.png"></image></view>
<view wx:else> <image class="uploadimageclass" bindTap="uploadfbphotothird" src="{{fbphotothird}}"></image></view>-->

微信小程序開發之三元運算符代替wx.if/wx.else