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

问题描述 投票:0回答:1

我使用助焊剂版本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>

    );

  }

}
reactjs atom-editor flux
1个回答
0
投票

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

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

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

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

const myDispatcher = new AppDispatcher();


var AppActions = {

  searchMovies : function(movie){

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

这只是一个例子,只是为了表明你的问题在哪里。

© www.soinside.com 2019 - 2024. All rights reserved.