vue 使用axios post方法传参到java后台

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/buyaopingbixiazai/article/details/89236792

使用官方的这种方法 后台取不到参数

方法1:
xios.post('/user', {
    firstName: 'Fred',
    lastName: 'Flintstone'
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });

方法二
// 发送 POST 请求
axios({
  method: 'post',
  url: '/user/12345',
  data: {
    firstName: 'Fred',
    lastName: 'Flintstone'
  }
});

 提供一种解决办法:

var params = new URLSearchParams();
params.append('userName', this.userName);
 params.append('account',this.account);
 axios.post('/aircraft/deptRoleBLH_findUserBy.do?',params)
                    .then(response => (this.Datas = response.data.json.userMaps))
                    .catch(error => console.log(error))

 
var params = new URLSearchParams();
params.append('userName', this.userName);
params.append('account',this.account);
axios.post('/aircraft/deptRoleBLH_findUserBy.do?',params)
.then(
response => (
    this.Datas = response.data.json.userMaps
))
.catch(error => console.log(error))

猜你喜欢

转载自blog.csdn.net/buyaopingbixiazai/article/details/89236792
今日推荐