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
Vue.js 使用Axios向DRF发送POST_Vue.js_Django Rest Framework_Axios - Fatal编程技术网

Vue.js 使用Axios向DRF发送POST

Vue.js 使用Axios向DRF发送POST,vue.js,django-rest-framework,axios,Vue.js,Django Rest Framework,Axios,我正试图使用vuejs中的axios库发出一个简单的POST请求,但由于某种原因,DRF没有收到参数。当通过Postman发出相同请求时,它将接收参数 VueJS postLogin(credentials){ return axios({ method: "POST", url: "company/login/", data: credentials, }).catch(err => { return TreatErrors

我正试图使用
vuejs
中的
axios
库发出一个简单的
POST
请求,但由于某种原因,
DRF
没有收到参数。当通过
Postman
发出相同请求时,它将接收参数

VueJS

postLogin(credentials){
    return axios({
      method: "POST",
      url: "company/login/",
      data: credentials,
    }).catch(err => {
      return TreatErrors.treatDefaultError(err);
    })
  }
DRF

@action(methods=['post'], detail=False)
    # Debug set here shows POST comes empty from vuejs
    def login(self, request, pk=None):
        if not request.POST.get('email'):
            raise ValidationError({
                'message': 'You must provide an email'
            })
使用
Chrome DevTools
我可以清楚地看到参数被发送到
DRF

我尝试过的 我尝试过从
Postman
处理每个
标题
,并将其粘贴到
axios
中,但没有任何运气

postLogin(credentials){
    return axios({
      method: "POST",
      url: "company/login/",
      data: credentials,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      }
    }).catch(err => {
      return TreatErrors.treatDefaultError(err);
    })
  }

基本上,我访问数据的方式是错误的:

由此:

if not request.POST.get('email'):
 raise ValidationError({
   'message': 'You must provide an email'
 })
对此

data = request.data

if not data.get('email'):
  raise ValidationError({
    'message': 'You must provide an email'
  })

非常感谢你!上帝保佑!:)