我试图在 componentDidMount 函数中获取数据后更改数据。
假设我正在获取一个对象:
{
text: "hello world"
}
但我想添加“!”在 componentDidMount 中获取后到此字符串。 我的问题是,我应该在哪里编辑获取的数据? 当我尝试在 componentDidMount 中编辑它时,我总是收到错误消息,指出我无法编辑“未定义”。
提前致谢。
最佳答案
更具体一点,如果你也展示你的获取函数和修改函数,那就更好了。但是,我可以猜测类似的东西:
componentDidMount() {
fetch(reqObj)
.then(json => {
const modifyJson = JSON.stringify(json) + '!'
this.setState({text: modifyJson})
})
}
关于javascript - 在 componentDidMount 中异步获取后更改/处理数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42118206/