The reason you are seeing '[object Object]' in the URL is because the 'query' parameter in the 'getVoucherListById' function is an object, and when you pass the 'query' object as a parameter to 'params', it gets converted to a string representation of the object, which is '[object%20Object]'.

To fix this, you need to correctly pass the 'query' object to the 'params' parameter using the 'URLSearchParams' class. Uncomment the commented code in your code snippet and update it as follows:

getVoucherList() {
  this.loading = true;
  if (!this.voucherGroupId) {
    return;
  }
  this.voucherQueryParam.accountsId = this.accountsId;
  this.voucherQueryParam.voucherGroupId = this.voucherGroupId;
  const params = new URLSearchParams(this.voucherQueryParam).toString();
  getVoucherById(params) // Update this line
    .then((res) => {
      console.log(res, "getVoucherList");
    })
    .catch((error) => {
      console.log(error);
    });
},

// Query voucher group list
export function getVoucherListById(query) {
  console.log(query, 'query'); // Update this line
  return request({
    url: '/financial/acvouchergrouprel/getVoucherListById',
    method: 'get',
    params: query
  });
}

By passing the 'query' object as 'params: query', it will be correctly serialized and appended to the URL, instead of being converted to '[object Object]'.

解决 URL 中出现 [object Object] 错误的技巧

原文地址: https://www.cveoy.top/t/topic/mZyc 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录