用法
getQueryParam 函数用于从 URL 获取指定查询参数的值。
import { getQueryParam } from '@movk/core'
getQueryParam('https://example.com?name=John&age=30', 'name')
// 'John'
getQueryParam('https://example.com?tags=a&tags=b', 'tags')
// 'a' (返回第一个值)
getQueryParam('https://example.com', 'name')
// null
API
getQueryParam(url, key)
从 URL 获取指定查询参数的值。
参数
url
string required
URL 字符串。
key
string required
参数名。
返回值
返回值
string | null
参数值,不存在返回
null。注意
- 如果参数有多个值,只返回第一个值
- 需要获取所有值请使用
getQueryParams
Changelog
No recent changes