如何将wx.openSetting的结果return给调用方?

发布于 7 年前作者 mluo13727 次浏览最后编辑 7 年前来自 ask

openSetting: async function () {

    return await wx.openSetting({

      withSubscriptions: true

    }).then(res=>{

      return res

    }).catch(err=>{

      return err

    })

  },

这种写法会发生“TypeError: Cannot read property ‘then’ of undefined”错误

查了一下,说wx.openSetting不接受Promise写法,那如何将返回数据return

给调用方?

2 回复
xia80
xia801 楼5 年前

我们可以自己封装一个 Promise

pingxie
pingxie2 楼5 年前

可以用回调函数

openSetting: function (cb{
  wx.openSetting({
    success (res) {
      cb(res)
    }
  })
 }