我刚刚开始使用Mobx,我正在尝试添加一个从可观察数组中删除项目的操作 . 我究竟做错了什么?
这是商店:
class ToDoStore {
@observable items = [];
@action addItem = (item) => {
this.items.push(item)
}
@action removeItem = (index) => {
this.items.splice(index, 1)
}
@computed get itemCount(){
return this.items.length;
}
}
这是App.js:
@inject('ToDoStore')
@observer class App extends Component {
handleRemove = (index) => {
this.props.ToDoStore.removeItem(index);
}
render() {
const {ToDoStore} = this.props;
return (
{ToDoStore.items.map((item, index )=>
{item} this.handleRemove(index)}>REMOVE)});
}
}
export default App;
这是我点击“删除”按钮时出现的错误