I am trying to get data by passing multiple ids as param.But the params i am passing is going as array which i don't want.
Example:
Current data: The api is returning param as details?ids[]=123&ids[]=245
Expected data: I would like to pass the param as details?ids=123&ids=245
const postRes = await axios.post('employee/departments', this.details);
const getRes = await axios.get('employee/departments',
{ params: { ids: postRes.map(i=>i.id)},
});
this.$emit('fileDetails', getRes.data);
You could serialize the parameters yourself:
'ids='
prefixed to the object's id
. &
delimiter.const params = postRes.map(i => 'ids=' + i.id) 1️⃣
.join('&') 2️⃣
const getRes = await axios.get('employee/departments?' + params)
Run this snippet for example output:
const postRes = [{ id: 11 }, { id: 22 }, { id: 33 }] const url = 'employee/departments?' + postRes.map(i => 'ids=' + i.id).join('&') console.log(url)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.