惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
有赞技术团队
有赞技术团队
H
Help Net Security
V
Visual Studio Blog
F
Fortinet All Blogs
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 司徒正美
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
腾讯CDC
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Stack Overflow Blog
Stack Overflow Blog
I
InfoQ
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
L
LangChain Blog
N
Netflix TechBlog - Medium
罗磊的独立博客
The GitHub Blog
The GitHub Blog
云风的 BLOG
云风的 BLOG
Hugging Face - Blog
Hugging Face - Blog
A
About on SuperTechFans
aimingoo的专栏
aimingoo的专栏
Recent Announcements
Recent Announcements

博客园 - 草率的龙果果

window 11 Ultra5‑125H,Arrow Lake 卡顿解决办法 npm配置内网,git配置内网 jenkins打包完镜像更新页面没有变化 vue2 element ui dialog拖拽功能实现。 AI整理提示词 数字转换为中文数字 前端数据导出excel工具函数 自动监测数据有效传输率统计算法说明 echarts官方扩展vue组件vue-echarts实现链接两个charts实现联动 OPPO商店签名认领应用 iframe跨域通信(postMessage) 博文阅读密码验证 - 博客园 Copilot键怎么改成Ctrl键? plus.downloader.createDownload 发送 POST 请求并携带 token vue2,vue3中在template中使用component组件is属性绑定jsx的vnode vue3 vite idea中control+鼠标单击不能跳转到文件定义的解决办法 vue/html-self-closing Vue2项目解决van-calendar 显示白色空白,需滑动一下屏幕,才可正常显示 Windows Terminal/Powershell 设置自动补全, 智能提示 【类似于mac的iterm2功能】 vue中使用axios获取不到响应头Content-Disposition的解决办法 ES7 新增方法:Array.prototype.some、Array.prototype.every 博文阅读密码验证 - 博客园 vue2使用openlayers10.3.0版本组包 javascript跨域问题排查
项目常用工具函数获取url参数和hash参数
草率的龙果果 · 2025-11-27 · via 博客园 - 草率的龙果果
export const getQueryString = (name, url) => {
	// 如果没有提供 URL,则默认使用 window.location.href
	if (!url) {
		url = window.location.href
	}

	// 创建一个 URL 对象
	const urlObj = new URL(url)

	// 尝试从查询字符串中获取参数值
	const queryParams = new URLSearchParams(urlObj.search)
	const queryValue = queryParams.get(name)
	if (queryValue) {
		return queryValue
	}

	// 如果查询字符串中没有找到,尝试从 hash 部分获取
	const hash = urlObj.hash

	// 手动解析 hash 部分的查询字符串
	const hashParts = hash.split('?')
	if (hashParts.length > 1) {
		const hashParams = new URLSearchParams(hashParts[1])
		return hashParams.get(name)
	}

	// 如果 hash 部分也没有找到,返回 null
	return null
}