合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
>[info] Object对象格式化为Query语法 ~~~ /** * @description对象格式化为Query语法 * @param { Object } params * @return {string} Query语法 */ export function objectToQuery(params: Record<string, any>): string { let query = '' for (const props of Object.keys(params)) { const value = params[props] const part = encodeURIComponent(props) + '=' if (!isEmpty(value)) { if (isObject(value)) { for (const key of Object.keys(value)) { if (!isEmpty(value[key])) { const params = props + '[' + key + ']' const subPart = encodeURIComponent(params) + '=' query += subPart + encodeURIComponent(value[key]) + '&' } } } else { query += part + encodeURIComponent(value) + '&' } } } return query.slice(0, -1) } ~~~