reactjs - 我在减速器中的语法有什么问题?
问题描述
我正在尝试向我的减速器添加调度。但是,我遇到了语法问题。我不确定如何解决此错误。我在减速器中使用 POST 方法。
export function insertSearchTerm(searchTerm) {
return (dispatch) => {
fetch('http://localhost:3001/api/v1/searches?searchterm='+searchTerm {
headers: {
'Content-Type':'application/json',
},
method:'POST',
body: JSON.stringify(searchTerm) searchTerm
}).then(res => console.log('D') {
dispatch({
type:'INSERT_TOP_SEARCH',
payload: res
})
}
)
}
}
./src/actions/insertSearchTerm.js
Line 4: Parsing error: Unexpected token, expected ","
2 |
3 | return (dispatch) => {
> 4 | fetch('http://localhost:3001/api/v1/searches?searchterm='+ searchTerm {
| ^
5 | headers: {
6 | 'Content-Type':'application/json'
7 | },
解决方案
在 searchTerm 之后添加 ','
return (dispatch) => {
fetch('http://localhost:3001/api/v1/searches?searchterm='+ searchTerm, {
headers: {
'Content-Type':'application/json'
}
}
}
推荐阅读
- magento - 登录 Magento 前端时出现 500 内部服务器错误?
- java - 在Python中修改条件表达式中的变量
- java - Solr Spellcheck 区分大小写的问题
- rust - 为什么 Rust 的向量索引语法不获取元素的所有权?
- powershell - 在什么情况下需要在 -NoTypeInformation *不 * 传递给 ConvertTo-Csv 或 Export-Csv 时发出的信息?
- node.js - 格式化我的 linux 分区后无法运行节点项目
- aws-lambda - Alexa SDK Card - 如何更改卡片中显示的文本的字体大小和字体类型
- java - ImageIO.read 找不到移动到子文件夹的文件
- c# - 调用在基泛型类中声明的非泛型方法会引发异常并带有消息
- ruby-on-rails - 发生 Ajax 请求时的 before_action 钩子