工作总结

.wpy文件点按钮分享时数据从后台获取如何去做

2021-06-29  本文已影响0人  轩轩小王子
async onShareAppMessage (res) {
      const { userId} = this.$parent.globalData
      const { orderId } = this
      let shareBtnType = ""
      if(res.from === 'button'){ // 避免点击右上角分享 报错
        const {type} = res.target.dataset//如果是自定义组件内的分享按钮,也可以这样区分
        shareBtnType = type
      }
      if(res.from === 'button' && (shareBtnType == 'redEnveBtn' || shareBtnType == 'redEnvelopesBtn')){
        const {title,image:imageUrl,shareKey} = await getShareRedEnveConfig(orderId,userId)//解构赋值
        const path = `pagesGroupBook/orderRedPacket/list?shareKey=${shareKey}&shareUserId=${userId}`
        return {
          title,
          path,
          imageUrl
        }
      }
     
    }

总结:

主要考虑用await、async来处理

![对小程序提供的api全都进行了promise处理]( image.png
上一篇下一篇

猜你喜欢

热点阅读