typescript 将 json 序列化为 querystring 格式

使用 typescript 时, 需要同时安装 @types/qsqs

1
yarn add @types/qs qs

demo

1
2
3
4
5
6
7
8
9
const params = qs.stringify({
    namespace: namespace,
    replicas: replicas,
})

const u = `/deployments/${name}/replicas?${params}`

console.log("Uuuuu::::", u);
// Uuuuu:::: /deployments/failed-nginx/replicas?namespace=default&replicas=3