【发布时间】:2018-07-31 21:06:57
【问题描述】:
我使用了两个类 我称第二类如下
let s = new SearchExtend();
output = s.fetchData(search)
alert(output)
第二个功能:
fetchData = (search) => {
fetch('http://example.com/search.php' , {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
// Getting the search.
search: search
})
}).then((response) => response.json())
.then((responseJson) => {
return responseJson;
})
.catch((error) => {
console.error(error);
});
}
但我进入“警报”未定义
当我使用 this.setState 而不是 return 时,出现以下错误:
警告 setstate(...) 只能更新挂载或挂载的组件
【问题讨论】:
-
让 form = new FormData(); s.fetchData(form ) 使用 FormData 并通过附加的形式传递参数和值 form.append("paramname", 'paramvalue') body:search no need JSON.stringify
标签: javascript reactjs react-native react-redux