【发布时间】:2016-02-16 11:59:03
【问题描述】:
我的 React 代码中看似不合理的行为。我在其中设置了两个元素,以在一行代码之后声明元素。我已经 console.log'ed 每个。两者都在分配之前正确打印,但只有比特币钱包变量(钱包)在状态中正确表示,而不是 imageLink。
module.exports = React.createClass({
getInitialState: function() {
return {
walletAddress: null,
image: null,
};
},
componentWillMount: function() {
Parse.User.currentAsync()
.then((user) => {
var wallet = user.get('address');
var imageLink = `https://api.qrserver.com/v1/create-qr-code/?size=500x500&data=bitcoin:${wallet}`;
console.log("wallet", wallet);
console.log("image: ", imageLink);
this.setState({image: imageLink});
this.setState({walletAddress: wallet});
console.log("imagezzz: ", this.state.imageLink);
})
},
【问题讨论】:
-
应该补充一下,我还尝试在一个分配中设置两个状态元素,即:this.setState({image: imageLink, walletAddress: wallet});。这也没有改变结果。
-
看起来您正在记录
state.imageLink(在console.log("imagezzz"...行),但您正在设置state.image。
标签: javascript reactjs react-native qr-code