条件渲染
vue:使用v-if指令,v-else表示v-if的else块,v-else-if表示v-if 的“else-if 块”
<div v-if="type === 'A'">
A
</div>
<div v-else-if="type === 'B'">
B
</div>
<div v-else-if="type === 'C'">
C
</div>
<div v-else>
Not A/B/C
</div>
微信小程序:使用wx:if,wx:else表示wx:if的else块,wx:elif表示wx:if的"else-if"块
<view wx:if="{{length > 5}}"> 1 </view>
<view wx:elif="{{length > 2}}"> 2 </view>
<view wx:else> 3 </view>
显示隐藏元素
vue 中VUE:v-show="..."
小程序中hidden="{{...}}"
绑定class
vue:全用v-bind,或者简写为:bind,和本有的class分开写
<div class="test" v-bind:class="{ active: isActive }"></div>
微信小程序:
<view class="test {{isActive ? 'active':'' }}"></view>
事件处理
VUE:使用v-on:event绑定事件,或者使用@event绑定事件
<button v-on:click="counter += 1">Add 1</button>
<button v-on:click.stop="counter+=1">Add1</button> //阻止事件冒泡
微信小程序:全用bindtap(bind+event),或者catchtap(catch+event)绑定事件
<button bindtap="clickMe">点击我</button>
<button catchtap="clickMe">点击我</button> //阻止事件冒泡
绑定值
VUE:vue动态绑定一个变量的值为元素的某个属性的时候,会在变量前面加上冒号:,例:<img :src="imgSrc"/>
微信小程序:绑定某个变量的值为元素属性时,会用两个大括号括起来。例:<image src="{{imgSrc}}"></image>
设置值
VUE:设置test的值可以用,this.test = true
;获取test的值可以用this.test.
微信小程序:设置test的值要用this.setData({test:true});
获取test的值用this.data.test