无法访问axios.post中的this.somefunction

时间:2019-02-05 07:23:11

标签: reactjs

class TimeEditor extends React.Component {
    constructor(props) {
      super(props);
      this.state = {
        code: 1,
        employeeID: 2,
        date:null,
        time:null
      };
    }
    callback_updateData()
    {
      this.props.loadData();
    }
    addNewTimestamp()
    {
      axios.post('/api/add_timestamp', {
        code: this.state.code,
        employeeID: this.state.employeeID,
        date: this.state.date,
        time: this.state.time
      })
      .then(function (response) {
        console.log(response);
        this.callback_updateData(); 
      })
      .catch(function (error) {
        console.log(error);
      });
    }

    }
  }

**我无法访问callback_updateData函数。请帮忙。

TypeError:无法读取未定义的属性'callback_updateData'     在:**

0 个答案:

没有答案