【问题标题】:dispatcher.dispatch() in action.js is giving me the error of dispatch is not a functionaction.js 中的 dispatcher.dispatch() 给了我 dispatch is not a function 的错误
【发布时间】:2019-09-07 20:56:30
【问题描述】:

我正在使用助焊剂版本 3.1.3

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

dispatch 不是函数

_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>

    );

  }

}

【问题讨论】:

  • 你能显示 AppDispatcher 文件吗?
  • AppDispatcher。 .js 文件。从 'flux' 导入 {Dispatcher} ;模块。出口=调度员;

标签: reactjs atom-editor flux


【解决方案1】:

您的问题基本上是您需要构建 Dispatcher。正如您在评论中所说,您正在导出 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;

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-19
    • 2021-10-02
    • 1970-01-01
    • 1970-01-01
    • 2022-08-03
    • 2020-04-24
    • 2015-05-04
    • 2018-07-23
    相关资源
    最近更新 更多