Javascript VueJS和axios-如何在post请求中访问数据

Javascript VueJS和axios-如何在post请求中访问数据,javascript,vue.js,axios,this,Javascript,Vue.js,Axios,This,我得到的数据如下: data: () => ({ input: { username: "", password: "" } }), loggin_in() { if (this.input.username != "" && this.input.password != "") { console.log(this.input.us

我得到的数据如下:

  data: () => ({
    input: {
      username: "",
      password: ""
    }
  }),
loggin_in() {
  if (this.input.username != "" && this.input.password != "") {
    console.log(this.input.username);
    axios
      .post("http://localhost:5000/login", {
        email: this.input.username,
        password: this.input.password
      })
      .then(function(data) {
        console.log(data);
      })
      .catch(function(error) {
        console.log(this.input.username);
      });
  }
}
并发出如下请求:

  data: () => ({
    input: {
      username: "",
      password: ""
    }
  }),
loggin_in() {
  if (this.input.username != "" && this.input.password != "") {
    console.log(this.input.username);
    axios
      .post("http://localhost:5000/login", {
        email: this.input.username,
        password: this.input.password
      })
      .then(function(data) {
        console.log(data);
      })
      .catch(function(error) {
        console.log(this.input.username);
      });
  }
}
记录第一个
this.input.username
可以工作,但是在那之后,我不知道如何访问数据<代码>此似乎未定义

Uncaught (in promise) TypeError: Cannot read property 'input' of undefined

我不知道为什么
这个
的上下文在这里发生了变化,并且不知道如何访问我的数据。有谁能解释一下发生了什么并帮我解决这个问题吗?

在回调中,您必须绑定它或使用箭头函数:

  .then(function(data) {
         console.log(data);
      })


在回调中,必须绑定此函数或使用箭头函数:

  .then(function(data) {
         console.log(data);
      })