action.js中的dispatcher.dispatch()给我分配错误不是函数

时间:2019-04-17 14:51:50

标签: reactjs atom-editor flux

我正在使用助焊剂版本3.1.3

我想知道调度程序为什么不工作。我遇到了错误:

  

调度不是函数

_dispatcher_AppDispatcher__WEBPACK_IMPORTED_MODULE_0__.default.dispatch is not a function

AppActions.js file

import AppDispatcher from '../dispatcher/AppDispatcher';
import AppConstants from '../constants/AppConstants';

var AppActions = {

  searchMovies : function(movie){

 AppDispatcher.dispatch({type:AppConstants.SEARCH_MOVIES,payload:movie});
  }
}
export default AppActions;

AppStore.js文件

var ApDispatcher = require('../dispatcher/AppDispatcher');
var AppConstants = require('../constants/AppConstants');
var EventEmitter = require('events').EventEmitter;
var Assign = require('object-assign');
var AppAPI = require('../utils/AppAPI');
var AppActions = require('../actions/AppActions');

SearchForm.js文件

class ApStore extends EventEmitter{

  action({type,payload}){

    switch (type) {

      case AppConstants.SEARCH_MOVIES:

        console.log(1);

        this.addTask(payload);

        break;

    }
  }

}

const store = new ApStore();

module.export = ApStore;

    import React from 'react';

import AppActions from '../actions/AppActions.js';


export default class SearchForm extends React.Component {

  onSubmit(e){

    e.preventDefault();

    var movie = {

      title : this.refs.title.value.trim()

    }

    //console.log("searchform.js"+movie.title);

    AppActions.searchMovies(movie);

  }

  render() {

    return (

      <div className="search-form">

          <h1 className="text-center">search for a movie</h1>

          <form onSubmit={this.onSubmit.bind(this)}>

              <div className="form-group">

                <input type="text" id="movieser" className="form-control" 
ref="title" placeholder="Enter movie name" />

              </div>

              <button className="btn btn-primary btn-block"> search 
movies</button>

          </form>

      </div>

    );

  }

}

1 个答案:

答案 0 :(得分:0)

您的问题基本上是您需要构造您的Dispatcher。正如您在评论中所说,您正在导出Dispatcher。但是您需要构造调度程序对象。

修改您的AppDispatcher.js或AppActions.js文件。

例如,将其添加到您的AppAction.js文件中:

5

这只是一个例子,只是为了说明您的问题所在。