Javascript 拉取api时未在redux中定义数据

Javascript 拉取api时未在redux中定义数据,javascript,reactjs,ecmascript-6,redux,es6-promise,Javascript,Reactjs,Ecmascript 6,Redux,Es6 Promise,我正试图使用redux来拉api,但我不能对它掉以轻心。我经常收到错误“错误数据未定义” 我正在使用CreateReact应用程序,添加了一些库,如thunk、logger和中间件。如果我忘了提什么,请说,这样我可以更新问题 这是我的行动 import axios from "axios"; export function fetchWeatherData() { return function (dispatch) { axios.get('http://api.openweathe

我正试图使用redux来拉api,但我不能对它掉以轻心。我经常收到错误“错误数据未定义”

我正在使用CreateReact应用程序,添加了一些库,如thunk、logger和中间件。如果我忘了提什么,请说,这样我可以更新问题

这是我的行动

import axios from "axios";

export function fetchWeatherData() {
return function (dispatch) {
    axios.get('http://api.openweathermap.org/data/2.5/forecast/weather?q=London&units=metric&lang=hr&APPID=example')
        .then((response) => {
            dispatch({type: "FETCH_WEATHER_DATA_FULFILLED",results: response.data})
        })
        .catch((err) => {
            dispatch({type: "FETCH_WEATHER_DATA_REJECTED", results: err})
        })
    }
}
这是减速机

 export default function reducer(state={
    cityName: data,
    nameOfCity: null,
    weatherDescription: null,
    windSpeed: null,
    temperature: null,
    maxTemperature: null,
    minTemperature: null
}, action) {
switch (action.type){
    case "FETCH_WEATHER_DATA": {
        return {...state,
            fetching: true
        }
    }
    case "FETCH_WEATHER_REJECTED": {
        return {...state,
            fetching: false,
            error: action.results
        }
    }
    case "FETCH_WEATHER_DATA_FULFILLED": {
        return {...state,
            fetching: false,
            fetched: true,
            nameOfCity: data.city.name,
            weatherDescription: data.list[0].weather[0].description,
            windSpeed: data.list[2].wind.speed,
            temperature: data.list[0].main.temp,
            maxTemperature: data.list[0].main.temp_max,
            minTemperature: data.list[0].main.temp_min
        }
    }
}

return state;
}
这是集装箱

import {FormContainer} from './containers/FormContainer';
import WeatherInfo from './components/WeatherInfo';
import {connect} from "react-redux"
import {updateInfo} from './actions/weather-apiActions'
import {fetchWeatherData} from './actions/weather-apiActions'

@connect((store) => {
  return {
    cityName: store.cityName.cityName,
    nameOfCity:store.nameOfCity.nameOfCity,
    weatherDescription:store.weatherDescription.weatherDescription,
    windSpeed:store.windSpeed.windSpeed,
    temperature:store.temperature.temperature,
    maxTemperature:store.maxTemperature.maxTemperature,
    minTemperature:store.minTemperature.minTemperature,
  }
 })

 class App extends Component {

   componentWillMount(){
     this.props.dispatch(fetchWeatherData());
   }

  }
存储文件

import { applyMiddleware, createStore } from "redux"

import logger from "redux-logger"
import thunk from "redux-thunk"
import promise from "redux-promise-middleware"

import reducer from "./reducers"

const middleware = applyMiddleware(promise(), thunk, logger())

export default createStore(reducer, middleware)
合并文件

import { combineReducers } from "redux"

    import cityName from "./weather-apiReducers"
    import nameOfCity from "./weather-apiReducers"
    import weatherDescription from "./weather-apiReducers"
    import windSpeed from "./weather-apiReducers"
    import temperature from "./weather-apiReducers"
    import maxTemperature from "./weather-apiReducers"
    import minTemperature from "./weather-apiReducers"

    export default combineReducers({
        cityName,
        nameOfCity,
        weatherDescription,
        windSpeed,
        temperature,
        maxTemperature,
        minTemperature
    })
编辑:显示错误的行。是减速器

./src/reducers/weather-apiducers.js中出错

6:15未定义错误“数据”无未定义 14:5警告预期为默认情况默认情况


✖ 2个问题(1个错误,1个警告)

未定义变量
数据。您必须使用
操作。结果

// ...
case "FETCH_WEATHER_DATA_FULFILLED": {
    return {...state,
        fetching: false,
        fetched: true,
        nameOfCity: action.results.city.name,
        weatherDescription: action.results.list[0].weather[0].description,
        windSpeed: action.results.list[2].wind.speed,
        temperature: action.results.list[0].main.temp,
        maxTemperature: action.results.list[0].main.temp_max,
        minTemperature: action.results.list[0].main.temp_min
    }
}
// ...

未定义变量
数据
。您必须使用
操作。结果

// ...
case "FETCH_WEATHER_DATA_FULFILLED": {
    return {...state,
        fetching: false,
        fetched: true,
        nameOfCity: action.results.city.name,
        weatherDescription: action.results.list[0].weather[0].description,
        windSpeed: action.results.list[2].wind.speed,
        temperature: action.results.list[0].main.temp,
        maxTemperature: action.results.list[0].main.temp_max,
        minTemperature: action.results.list[0].main.temp_min
    }
}
// ...
I持续获取错误“未定义错误数据”
-哪一行代码导致此持续错误?
I持续获取错误“未定义错误数据”
-哪一行代码导致此持续错误?