[TOC]
# wx:if
```
<view wx:if="{{condition==1}}">
吃米饭
</view>
<view wx:elif ="{{condition ==2}}">
吃粥
</view>
<view wx:else>
不吃
</view>
```
```
Page({
data:{
condition : Math.floor(Math.random()*3+1)
}
})
```
## demo
### 1.使用点击事件,实现图片切换
```
<image bindtap = "click" wx:if="{{show}}" src="/images/tab/ciwei.png"/>
<image bindtap = "click" wx:else src="/images/tab/ciwei_hl.png"/>
```
```
//js
Page({
data: {
show:false
},
click(){
if(this.data.show){
this.setData({
show:false
})
}else{
this.setData({
show:true
})
}
}
})
```
### 2.使用三元表达式
```
<image bindtap = "click" src="{{show?'/images/tab/ciwei.png':'/images/tab/ciwei_hl.png'}}"/>
```