解决小程序开发自定义组件getCenterLocation无法回调问题

在创建map上下文时第二个参数传入this

ready: function () {
    this.mapCtx = wx.createMapContext('myMap', this);
},
methods: {
    mapChange: function() {
        let self = this;
        this.mapCtx.getCenterLocation({
          success: function(res) {
            console.log(res)
            self.setData({
              nearList: [],
              latitude: res.latitude,
              longitude: res.longitude,
            })
          }
        })
    }
}
posted @ 2019-07-24 09:16  沉默-是金  阅读(1002)  评论(0编辑  收藏  举报