Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Vue2中标头中的Axios POST请求错误_Node.js_Vue.js_Vuejs2_Axios - Fatal编程技术网

Node.js Vue2中标头中的Axios POST请求错误

Node.js Vue2中标头中的Axios POST请求错误,node.js,vue.js,vuejs2,axios,Node.js,Vue.js,Vuejs2,Axios,我不熟悉javascript和Vue.js 我正在使用axios在Vuejs中进行POST API调用,我的后端在node.js中。我的授权有误。在《邮递员》中效果很好 我的POST API调用如下所示: import Vue from 'vue' import router from '../router' import axios from 'axios' const API_URL = 'http://localhost:8000/api/' const

我不熟悉javascript和Vue.js

我正在使用axios在Vuejs中进行POST API调用,我的后端在node.js中。我的授权有误。在《邮递员》中效果很好

我的POST API调用如下所示:

import Vue from 'vue'
    import router from '../router'
    import axios from 'axios'

    const API_URL = 'http://localhost:8000/api/'
    const LOGIN_URL = API_URL + 'login'

    export default {
    login(credentials, redirect) {
    console.log(LOGIN_URL)
    axios.post(LOGIN_URL,{
    headers: {
    'Authorization': 'Basic YWtzaGF5OmFrc2hheQ==',
    'Content-Type': 'application/json',
    'Accept': 'application/json'
    },
    data: {
    'email': credentials.email,
    'password': credentials.password
    }
  }).then(response => {
  console.log(response.data)
  router.push(redirect)
  }).catch(e => {
  console.log(e);
  })
  }
  }
当我发出api请求时,我的javascript控制台显示

Failed to load resource: the server responded with a status of 500(Internal Server Error)
我的服务器控制台显示错误

TypeError: Cannot read property 'username' of undefined

这里的用户名是基本授权中的用户名。

在您的数据帖子中,您没有发送用户名字段,只有电子邮件和密码,我认为您应该包含用户名。服务器不需要用户名。用户名字段用于标题授权您尚未包含所有相关代码。错误清楚地表明,它试图从一个空变量或未定义
username
的变量中读取属性
username
。我们需要查看服务器代码才能获得更多帮助。服务器试图从哪个对象读取“用户名”字段?在您的数据帖子中,您没有发送用户名字段,只有电子邮件和密码,我认为您应该包含用户名。服务器不需要用户名。用户名字段用于标题授权您尚未包含所有相关代码。错误清楚地表明,它试图从一个空变量或未定义
username
的变量中读取属性
username
。我们需要查看服务器代码才能获得更多帮助。服务器试图从哪个对象读取“用户名”字段?