Uni-app v-if的写法

在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>

 

posted @ 2021-10-02 16:29  RookieCoderAdu  阅读(2927)  评论(0编辑  收藏  举报