Django后台获取不到前端axios-post请求提交的参数的解决方法

解决方法

用 URLSearchParams 传递参数

let param = new URLSearchParams()
param.append('username', 'admin')
param.append('pwd', 'admin')
axios({
    method: 'post',
    url: '/api/lockServer/search',
    data: param
})

完整代码:

        let that  = this;
        let param = new URLSearchParams();
        param.append('name', that.ruleForm.name);
        param.append('server', that.ruleForm.server);
        param.append('org', that.ruleForm.org);
        param.append('desc', that.ruleForm.desc);
        
        this.$refs[formName].validate((valid) => {
          if (valid) {
            that.$axios({
              method: 'post',
              url: 'http://localhost:9999/article/check_form/',
              data: param
            })
            .then(function(res){
              if(res.data.ret){
                that.$message('提交成功!');
                that.$refs[formName].resetFields();
                that.$router.push('/tag');
              }
            })
            .catch(function(err){
              console.log(err);
            })
          } else {
            that.$message('error submit!!');
            return false;
          }
        });

参考文章:https://blog.csdn.net/csdn_yudong/article/details/79668655

你可能感兴趣的:(axios,Django)