onClick={() =>history.push('/index/list_info?id=88')}
const urlArr = location.search; //获取url中"?"符后的字串 ?
let id;
let str;
let strS;
if(urlArr.indexOf("?") != -1) {
str = urlArr.substring(1);
strS = str.split("=");
id= strS[1]; //获取id值
}
React 中获取url中的参数值
最新推荐文章于 2024-09-28 17:19:58 发布
这篇文章展示了如何在JavaScript中通过onClick事件处理函数,利用history.push更新URL,并从URL查询字符串中提取id值。它使用location.search获取URL的查询部分,然后通过split方法解析参数。
506

被折叠的 条评论
为什么被折叠?



