关于vue 中的 axios 的post 请求命令 中的参数

前端的萤火虫 发布于 2017/03/09 10:51
阅读 27K+
收藏 0

var config={
              method:'post',
              url: "/backUser/login",
              data:{username:'advance',password:123456},
              headers: {'X-Requested-With': 'XMLHttpRequest'},
              requestHeader:{'Content-Type':'application/json'},
              responseType: '

        }

axios(config).then(function(res){console.log(res)}).catch(function(err){console.log(err)})

OPTIONS http://120.77.246.117:8080/momingtang/backUser/login 403 (Forbidden)
XMLHttpRequest cannot load http://120.77.246.117:8080/momingtang/backUser/login. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8085' is therefore not allowed access. The response had HTTP status code 403.
Login.vue?49ba:70

Error: Network Error
    at createError (eval at <anonymous> (app.js:1860), <anonymous>:15:15)
    at XMLHttpRequest.handleError (eval at <anonymous> (app.js:1842), <anonymous>:87:14)

加载中
0
LikesWinds
LikesWinds
var config = {
  method: 'post',
  url: '/backUser/login',
  data: {username: 'advance', password: 123456},
  transformRequest: [
    function(data) {
      let ret = ''
      for (let it in data) {
        ret += encodeURIComponent(it) +
          '=' +
          encodeURIComponent(data[it]) +
          '&'
      }
      return ret
    }
  ]
}

 

0
毛巳煜
毛巳煜
axios({
  method: 'get',
  url: 'http://10.32.156.86:8082/w/contractPage/pageSize',
  params: {
    pageSize: '1'
  }
}).then(function (response) {
  alert(JSON.stringify(response.data));
}).catch(function (error) {
  alert(error);
});
0
毛巳煜
毛巳煜

data 改成 params

0
前端的萤火虫

已经解决了,多谢各位啦

啥不懂
啥不懂
怎么解决的
0
r
rayesty

怎么解决的

0
c
coolcgp
该评论暂时无法显示,详情咨询 QQ 群:点此入群
0
c
coolcgp

前端的萤火虫

2个月前 粘贴的图片是对的,已使用。

0
Mixr
Mixr
​
let data = [
  ["user", ''],
  ["pwd", ''],
];
let url_params = new URLSearchParams(data);
axios({
  method: 'get',
  url: '',
  data: url_params
}).then(() => {
    //....
})

试试看这样可行不

OSCHINA
登录后可查看更多优质内容
返回顶部
顶部