js 参数序列化

export const getParamsToString = (obj) => {
  let str = '';
  for (const key in obj) {
    str += `${key}=${obj[key]}&`;
  }
  return str.substr(0, str.length - 1);
};

export const getParamsToString1 = (obj) => {
  let str = '';
  for (const key in obj) {
    str += `${key}=${encodeURIComponent(obj[key])}&`;
  }
  return str.substr(0, str.length - 1);
};

 

posted @ 2020-12-31 11:02  拈花醉  阅读(1274)  评论(0编辑  收藏  举报