@vincent15000 did not work. Was thinking of writing some messy function for this but realised you can do this :
const filter = reactive({
name: route.query['filter[name]'] ?? '',
attributes:{
color: route.query['filter[attributes][color][]'] ?? [],
size: route.query['filter[attributes][size]'] ?? '',
}})
then I can use it like this
<input type="text" v-model="filter.name">
To convert back, I couldn't avoid this messy function
let query = '?page='+pageno+objectToQuery('filter',filter);
const objectToQuery = (field, obj, prefix = null) => {
let query = "";
if (obj) {
let keys = Object.keys(obj);
keys.forEach((key) => {
if (Array.isArray(obj[key])) {
obj[key].forEach((e) => {
if (e != null) query += '&'+field + (prefix ?? "") + "[" + key + "]" + "[]=" + e;
});
} else if (typeof obj[key] === "object" && !Array.isArray(obj[key])) {
query += objectToQuery(field, obj[key], (prefix ?? "") + "[" + key + "]");
} else {
if (obj[key] != null) query += '&'+field + (prefix ?? "") + "[" + key + "]=" + obj[key];
}
});
}
return query;
};
is there a better way to convert the object back to a query string?