用法
stringifyQuery 函数用于将对象序列化为查询字符串。
import { stringifyQuery } from '@movk/core'
stringifyQuery({ name: 'John', age: 30 })
// 'name=John&age=30'
stringifyQuery({ tags: ['a', 'b', 'c'] })
// 'tags=a&tags=b&tags=c'
stringifyQuery({ name: '中文' })
// 'name=%E4%B8%AD%E6%96%87'
stringifyQuery({ a: null, b: undefined, c: '' }, { skipNull: true, skipEmpty: true })
// ''
API
stringifyQuery(params, options?)
将对象序列化为查询字符串。
参数
params
QueryParams required
查询参数对象。
options
object
序列化选项。
options.skipNull
boolean
跳过
null 和 undefined 值。options.skipEmpty
boolean
跳过空字符串。
options.arrayFormat
'repeat' | 'bracket' | 'index' | 'comma'
数组格式:
repeat(默认)、bracket、index、comma。返回值
返回值
string
查询字符串(不含
?)。Changelog
No recent changes