前端(1) post

methods:{
        doLogin:function(){
            this.username
            this.password
            this.$axios.request({
                url:'http://127.0.0.1:8000/api/v1/auth/',
                method:'POST',
                data:{
                    user:this.username,
                    pwd:this.password
                },
                headers:{
                    'Content-Type':'application/json'
                }
            }).then(function(arg){
                console.log(arg)

            }).catch(function(arg){
                console.log(发生错误)

            })
        }
    }

后端(1)

from rest_framework.views import APIView
from rest_framework.response import Response

class AuthView(APIView):
    def options(self, request, *args, **kwargs):
        # 进行预检
        obj = Response('')
        obj['Access-Control-Allow-Origin'] = '*'
        obj['Access-Control-Allow-Headers '] = 'Content-Type'
        obj['Access-Control-Allow-Methods '] = 'PUT,POST,DELETE'
        return obj

    def post(self,request,*args,**kwargs):

        obj = Response('')
        obj['Access-Control-Allow-Origin'] = '*'
        return obj

后端(1.2)

12-23 14:32
查看更多