【vue】post请求接口时,以数组的形式传参处理方法
需求:做搜索时候的需求,需要给后端传数组控件:<el-selectv-model="search.projectUuidList"placeholder="请选择项目名称"filterableclearable@change="searchHandler"><el-optionv-for="item in projects":key="item.proje.
·
需求:
做搜索时候的需求,需要给后端传数组
控件:
<el-select
v-model="search.projectUuidList"
placeholder="请选择项目名称"
filterable
clearable
@change="searchHandler"
>
<el-option
v-for="item in projects"
:key="item.projectUuid"
:label="item.name"
:value="item.projectUuid"
>
</el-option>
</el-select>
数据:
data() {
return {
search: {
projectUuidList: [],
page: 0,
pageSize: 20
},
}
}
连获取控件的接口,这里就要传数组了
loadData() {
this.loading = true;
let post = { ...Object.assign({}, this.search) };
//!!!!!!!
post.projectUuidList = post.projectUuidList ? [post.projectUuidList] : [];
this.$axios
.post(`${CUSTOMER_URL}/api/confirmation/page`, post)
.then(response => {
if (response.data.code == 0 && response.data.data) {
this.list = response.data.data.pageData;
this.loading = false;
})
.catch(error => {
if (error.response.data) {
this.$message.error(error.response.data.error);
}
});
},
👇
post.projectUuidList = post.projectUuidList ? [post.projectUuidList] : [];
更多推荐
已为社区贡献5条内容
所有评论(0)