javascript - 如何在Javascript中绑定一个函数
问题描述
我想在自身内部绑定函数,这样我就可以使用这个 setState 改变状态帮助我解决这个问题
function(response){
this.function=this.function.bind(this)
console.log(response)
}
解决方案
试试这个希望对你有用
axios.post(" http://${REACT_APP_SERVER_URL}/facebook", { uid: user }).then((response) => {
console.log('hello')
if (response.data.success) {
const { checked } = this.state;
const newChecked = [...checked];
newChecked.push(1)
this.setState({ checked: newChecked });
console.log(this.state.checked)
history.push("/dashboard");
}
}).catch(err=>{
console.log(err)
})
推荐阅读
- python - 多线程应用程序中的 _wait_for_tstate_lock 错误
- java - 球衣注入 AbstractBinder 没有调用配置
- c - 仅在删除链表的第一个节点时收到“双重释放或损坏”
- python - 在 PyQt5 中为方法添加进度条
- javascript - 为什么在这个 tensorflowjs 代码中 chrome 给出了错误的输出而 firefox 给出了正确的输出?
- javascript - JS中的批量异步请求
- angular - 如何以角度返回订阅
- django - 无法连接到服务器:连接被拒绝 (0x0000274D/10061) - 远程服务器上的 PostgreSQL
- airflow - 气流任务调度器
- c++ - 在 do-while 循环中有一个变量列表,但在 while 部分它错误“无法将 '(void)0' 转换为 bool