2017-01-23 5 views
0

は私axiosのURLアクションへのAPIからURLを渡す方法(ReactJS)

import Api from '../middleware/api' 
    export function IncomeList() { 

     return dispatch => { 

      return (

       axios.post(Api.getURI(outline),{}, { 
      headers: { 'X-Authenticated-Userid': '[email protected]' } 
     }).then(function (response) { 


        console.log(response.data); 
        dispatch(receiveData(response.data.body)); 

       }) 
      .catch((error) => { 
        console.log(error); 
       }) 
       ) 
     } 
    } 

にこれを渡してみAPIファイル

import { apiUrl } from '../config' 
const baseUri = apiUrl 
const uri = { 
outline : '/course/income/outline' 
} 
const getURI = (key) => baseUri + uri[key] 

module.exports = { apiMiddleware, get, post, put, ...{ delete: del }, uri, getURI } 

を取得します。しかし、私はエラーが捕捉されないにReferenceErrorを得る:アウトラインが定義されていません。正しいURLを渡すには? getURI方法にリテラル

答えて

1

パス列:

Api.getURI('outline') 

Api.getURI(outline)の呼び出しは、現在のスコープ(したがってにReferenceError)に定義されていないoutline変数のインタプリタの外観を作ります。

Protip:linterは、ESLintのように、このエラーを早くキャッ​​チします。

+0

спасибо!)работает –

+0

@ЕгорКротенкоはここに英語を張りましょう:)そうでなければ、あなたは大歓迎です。 – Pavlo

関連する問題