有时候在react项目中会遇到表格数据实时修改的的需求,话不多说,直接上代码。
index.state.js中可以写
import { observable, action, toJS } from ‘mobx’;
class State {
@observable data = [];
@observable columns = [
{
title: ‘name’,
dataIndex: ‘name’,
width: ‘25%’,
editable: true
},
{
title: ‘age’,
dataIndex: ‘age’,
width: ‘15%’,
editable: true
},
{
title: ‘address’,
dataIndex: ‘address’,
width: ‘40%’,
editable: true
},
{
title: ‘edit’,
dataIndex: 'edit
}
];
}
export default new State();
index.component.jsx中写的代码
import React from ‘react’;
import { observer } from ‘mobx-react’;
import { Table, Input, InputNumber, Popconfirm,