search

Home  >  Q&A  >  body text

javascript - reflux报错:[object Object] is missing a listen method?

写了一个很简单的reflux练习,浏览器报错:[object Object] is missing a listen method ,找不到原因在哪,求各位帮助,非常感谢!
store.js:

Reflux.createStore({
    items:[],
    listenables: [actions],
    onGetAll () {
        this.trigger({list:this.items});
    },
    onAdd(item){
        this.items.push({name:item});
        this.trigger({list:this.items});
    },
    onRemove(i){
        this.items.remove(i);
        this.trigger({list:this.items});
    }
});

actions.js:

export default Reflux.createActions(['getAll','add','remove']);

component.js

export default class Todo extends React.Component{
    componentDidMount() {
        actions.getAll();
    }

    add(){
        var item = this.refs.item.value;
        this.refs.item.value='';
        actions.add(item);
    }

    remove(i){
        actions.remove(i);
    }

    render() {
        //items用于乘放li的集合
        let items;
        if (this.state.list) {
            items = this.state.list.map( (item,i) => {
            
                return <li key = {i}>
                    {item.name}
                    <button onClick = {this.remove.bind(this,i)}>remove</button>
                </li>
            })
        }
        return (
                <button onClick={this.add.bind(this)}>add</button>
        )
    }
}

ReactMixin.onClass(Todo, Reflux.connect(store));
PHP中文网PHP中文网2821 days ago420

reply all(1)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-10 17:15:57

    应该是你的store组件没有暴露出去吧?我也是犯了这个错误才发现的 你store应该用的是ES5的写法(其实我也是 TTT)

    reply
    0
  • Cancelreply