有关setdata问题?

发布于 8 年前作者 ming4811150 次浏览最后编辑 8 年前来自 ask
console.log("befor:" + that.shareImg);
that.setData({ shareImg: res.tempFilePath });
console.log("after:" + that.shareImg);
console.log(res.tempFilePath);
输出如下:
befor:undefined
after:undefined
http://tmp/wxb4f060XXXXXX7.png
undefined

那个shareimg我还有赋初始值,然而一样是未定义?不懂

js里面怎么才能用全局变量,困扰了一周,求救

3 回复
mingguo
mingguo1 楼5 年前
that.data.shareImg
tao22
tao222 楼5 年前

什么意思?你要获取data中的数据是that.data.shareImg

yuanqiang
yuanqiang3 楼5 年前
console.log("before:" + that.data.shareImg);
console.log("after:" + that.data.shareImg);