在Uni-app中,v-if 支持以下類型
假如存在以下變量
data(){ return{ isShow:true, sex:2 } }
1.bool類型的變量
<view v-if="isShow" style="width:300upx;height:300upx"> 顯示 </view> <view v-else style="width:300upx;height:300upx"> 不顯示 </view>
2.三元表達式
<view v-if="isShow==1?true:false" style="width:300upx;height:300upx"> 顯示 </view>
3.判斷表達式
<view v-if="sex==0" style="width:300upx;height:300upx"> 男性 </view> <view v-else-if="sex==1" style="width:300upx;height:300upx"> 女性 </view> <view v-else style="width:300upx;height:300upx"> 性別未知 </view>