🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
~~~ //wxml //子组件 <view class="like" catchtap="onLike"> <text>{{count}}</text> </view> ~~~ ~~~ //js onLike(event){ var like = this.properties.like; var count = this.properties.count; if(like){ this.setData({ like:false, count:count-1 }) }else{ this.setData({ like:true, count:count+1 }) } /* 自定义事件 */ var behavior = this.properties.like?"like":"cancel"; this.triggerEvent('like',{ behavior }) ~~~ ~~~ //父组件 <v-like bind:like="onLike"></v-like> ~~~ ~~~ //js onLike(e){ console.log(e.detail); } ~~~