小程序中用setData()给data重新赋值为什么会说变量没定义?

Page({
    data:{
        img : ''
    },
    GetImages: function(){
        var that = this;
        wx.chooseImage({
            count: 1, // 默认9
            sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
            sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
            success: function (res) {
            // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
            that.setData({
                img: res.tempFilePaths
            })
            console.log(img)
            }
           })
    }
})

报错信息是:img is not defined;at pages/randomint/randomint onReady function;at api chooseImage success callback function
ReferenceError: img is not defined

希望各位大佬能帮忙!

你console.log(img);的时候img当然是没有定义的啊

不会是你img后面加了个空格吧

log(that.data.img)试试

 

谢谢,我以为他说的没有定义是setData那边,没有想到是下面那句里