【发布时间】:2016-12-27 18:34:05
【问题描述】:
我一直在将一个简单的 React 项目从 ES5 转换为 ES6, 7 但我遇到了问题。打开 index.html 时出现此错误:
我研究了一些常见的修复方法:
- 更新反应
(15 应该有完整的 ES6 支持吗?)
- 导入或循环依赖中的拼写错误
resultConstants.js
export const RESULTS = {
RECEIVED_SEARCH: "RECEIVED_SEARCH",
RECEIVED_RESULTS: "RECEIVED_RESULTS"
};
dispatcher.js
import { Dispatcher } from 'flux';
const AppDispatcher = new Dispatcher();
export default AppDispatcher;
但我还没有真正看到这个问题。这是导致问题的商店。
import AppDispatcher from '../dispatcher/dispatcher';
import { RESULTS } from '../constants/resultConstants';
import { FluxStore } from 'flux';
let _query = 'restaurant',
_results = [];
const _mapOptions = {
...
};
class ResultStore extends FluxStore {
query() {
return _query;
}
mapOptions() {
return _mapOptions;
}
all() {
return _results.slice(0, 9);
}
__onDispatch(payload) {
switch(payload.type) {
case RESULTS.RECEIVED_SEARCH:
_resetQuery(payload.search.query)
_resetCenter(payload.search.center);
resultStore.__emitChange();
break;
case RESULTS.RECEIVED_RESULTS:
_resetResults(payload.results);
resultStore.__emitChange();
break;
default:
return;
}
}
}
function _resetQuery (query) {
_query = query;
}
function _resetCenter (center) {
_mapOptions.center = center;
};
function _resetResults (results) {
_results = results;
};
export const resultStore = new ResultStore(AppDispatcher);
即使我包含这段代码的 sn-p 也要清楚:
constructor() {
super();
}
它仍然会出现这个错误。
问题
- 出现此错误的其他一些原因是什么?
- 我的 ES6 怎么样? (赞赏有建设性的批评)
【问题讨论】:
-
检查这个问题是否有其他可能的问题/错别字:stackoverflow.com/questions/30116430/…
-
您确定
FluxStore存在吗?如果你log那,我打赌你会得到undefined。
标签: javascript reactjs ecmascript-6 flux