【问题标题】:'Argument expression expected' error during ajax call in rxjsrxjs 中的 ajax 调用期间出现“预期参数表达式”错误
【发布时间】:2019-11-12 17:48:35
【问题描述】:

使用 api 调用后出现此错误。我正在尝试从 myjson api 获取数据。我是在当前的实现中做错了什么,还是有更好的方法来调用相同的 api。

import { createAction, handleActions } from 'redux-actions'
import { PLUGIN_NAME, STORE_MOUNT_POINT } from '../constants'
import { Epic,ofType } from 'redux-observable'
import { Store } from '../Store'
import { defer, of } from 'rxjs'
import { mergeMap } from 'rxjs/operators'
import { ajax } from '../util'

const fetchReportTemplate$: Epic<Store.IFSA> = (action$, state$) =>
  action$.ofType(startFetchReportsTemplate.toString(),
      return  ajax(
          {
            url: 'https://api.myjson.com/bins/15dcd9',
            body: ''
          }
        )
      ).map(({ response: { data } }) => {
        return of(clearAllHttpErrors(), receiveReportsTemplateRows(data))
        })

【问题讨论】:

    标签: javascript reactjs react-redux rxjs rxjs6


    【解决方案1】:

    是的,这是您的代码中的语法错误。

    action$.ofType(startFetchReportsTemplate.toString(),
          // here, floating return without function
          return  ajax(
    

    【讨论】:

    • 要不要在return之前写一个函数?
    • 是的,但这不是唯一的问题——你可能应该做类似 action$.pipe(ofType(type), map(() => ajax(...)), map((响应) => doSth(...) ) redux-observable.js.org/docs/basics/Epics.html
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多