限时免费试用:欢迎注册 api.bigmodel.org ,快速体验大模型 API 接入服务。
当前位置:首页 >开发者 >网站框架 >小程序

小程序 | 插件中事件的激活

分类:小程序时间:2018-09-10浏览:3086
// 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', {}, {})
      }
    }

  }
本站文章如未注明出处均为原创,转载请注明出处,如有侵权请邮件联系站长。
0/500
Share your thoughts respectfully.