uniapp 在回调函数中赋值 is not an object

uniapp 在回调函数中赋值

解决 is not an object 错误

            chooselocation(){
                uni.chooseLocation({
                    success: function (res) {
                     this.position = res.name;
                     console.log('位置名称:' + res.name);
                     console.log('详细地址:' + res.address);
                     console.log('纬度:' + res.latitude);
                     console.log('经度:' + res.longitude);
                 }
                })
            },

上面的代码就会出现is not an object 错误

修正为

            chooselocation(){
                var that = this;
                uni.chooseLocation({
                    success: function (res) {
                     that.position = res.name;
                     console.log('位置名称:' + res.name);
                     console.log('详细地址:' + res.address);
                     console.log('纬度:' + res.latitude);
                     console.log('经度:' + res.longitude);
                 }
                })
            },

赋值正确。

转载于:https://www.cnblogs.com/masterchd/p/11147654.html

你可能感兴趣的:(uniapp 在回调函数中赋值 is not an object)