vue axios发布如何提交formdata数组?

问题描述 投票:0回答:2

我需要提交阵列数据,因为后端只能识别此类数据

预期效果:

&row[weigh]=0
&row[status]=normal

代码:

row:{
  weigh: 0,
  status: 'normal'
}

实际效果:

row:{
  weigh: 0,
  status: 'normal'
}

当我提交数据时,控制台显示JSON而不是Array,但后端无法获取它

我需要与以下表单提交的结果保持一致

<input class="form-control" size="50" name="row[a]" type="text" value="">
<input class="form-control" size="50" name="row[b]" type="text" value="">
vue.js axios
2个回答
0
投票
public register(rowObject: RowObject): AxiosPromise<any> {
    return axios.post('http://localhost/api/register', rowObject);
}

这样您可以通过Post方法传递数据。

rowObject =  {
    weigh: 0,
    status: 'normal'
    }

0
投票

您的代码也应该像这样传递一个数组。

data = [
  {weigh: 0},
  {status: 'normal'}
]

然后,例如,使用axios将其发送到服务器时,您的代码应如下所示

axios.post('/api endpoint', {row:data})
    .then(response => {
     // response here
});
© www.soinside.com 2019 - 2024. All rights reserved.