javascript - 遇到this.state不是函数错误
问题描述
当我尝试运行我的代码时,我得到了error this.setState is not a function
deos,任何人都知道我该如何纠正这个问题?谢谢!
spiele.listUsers(params, function(err, data) {
if (err) console.log(err, err.stack);
else console.log(data)
const ball = data;
this.setState({
ball
}).bind(this)
});
解决方案
你.bind
在错误的地方使用
spiele.listUsers(params, function(err, data) {
if (err) console.log(err, err.stack);
else console.log(data)
const ball = data;
this.setState({
ball
}).bind(this) // wrong
});
.bind
应该在function(err, data)
不在this.setState
spiele.listUsers(params, function(err, data) {
if (err) console.log(err, err.stack);
else console.log(data)
const ball = data;
this.setState({
ball
})
}.bind(this)); // correct
推荐阅读
- model-view-controller - 从控制器操作发布到第三方网站
- javascript - Vuetify.js 和日期选择器手表不会在月份触发
- php - Codeigniter, mysql, select_max... 不同列值时插入
- excel - 宏的执行不起作用(Excel 2016)
- scala - scala代码错误将unixtimestamp转换为数据帧中的日期时间格式
- css - 将具有百分比 (%) 宽度的 div 设置为其最大内容的最小宽度
- c# - 网格未使用所有可用空间
- python - 修改视频帧,但在 python skvideo ffmpeg 中保留它们的时间戳
- c++ - “new int * **[10]”有什么作用?
- r - 增加字符串以支持> 4000个字符限制的方法?