如果你对该文章中的内容有疑问/不解,可以点击此处链接提问
要注明问题和此文章链接地址 点击此处跳转
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
// components/like/index.js Component({ /** * 组件的属性列表 */ properties: { like:{ type:Boolean//默认false }, count:{ type:Number//默认0 } }, /** * 组件的初始数据 */ data: { // like:false, // count:9, yesSrc:'images/like.png', noSrc:'images/like_no.png' }, /** * 组件的方法列表 */ methods: { onLike:function(event){ // console.log(event) let like=this.properties.like let count=this.properties.count count = like?count-1:count+1 this.setData({ count:count, like:!like }) //设置事件激活事件 let behavior=this.properties.like?'like':'cancel' this.triggerEvent('like',{ behavior:behavior },{}) } } }) ????????????????? --------------- /** * 组件的方法列表 */ methods: { onLeft:function(event){ //如果不是最后一期,则触发 if(!this.properties.latest){ this.triggerEvent('left', {}, {}) } }, onRight: function (event) { //如果不是第一期,则触发 if(!this.properties.first){ this.triggerEvent('right', {}, {}) } } } |