componentDidMount() { eventProxy.on('event', async (id) => { const getList = (id) => { return $http.get('api/list' + id) .then(res => res.data.data) } const list = await getList(id) console.log(list) this.setState({ data: list}, () => console.log(this.state.data)) })}整个方法写在componentDidMount()函数里,eventProxy会监听一个event事件,并接收一个id参数,在回调函数中使用这个id参数发送请求获取一个数组,再将这个数组赋值到this.state.data。然而,console.log(list)这句话已经成功打印出数组了,console.log(this.state.data)这句却并没有执行,请问是为什么呢?应该怎么解决?by the way, state.data 在初始化的时候是个空数组。
添加回答
举报
0/150
提交
取消
