微信小程序开发之三元运算符代替wx.if/wx.else

  直接上代码

实现功能为:当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>-->

转载于:https://www.cnblogs.com/min-min-min/p/6875504.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值