当前位置:网站首页>Get URL of [url reference]? For the following parameters, there are two ways to get the value of the corresponding parameter name and convert the full quantity to the object structure
Get URL of [url reference]? For the following parameters, there are two ways to get the value of the corresponding parameter name and convert the full quantity to the object structure
2022-07-25 05:40:00 【Your beloved brother Qiang】
visit Your beloved brother Qiang _ Baidu search https://www.baidu.com/s?wd=%E4%BD%A0%E6%8C%9A%E7%88%B1%E7%9A%84%E5%BC%BA%E5%93%A5&rsv_spt=1&rsv_iqid=0xda37fa0900670da8&issp=1&f=8&rsv_bp=1&rsv_idx=2&ie=utf-8&tn=baiduhome_pg&rsv_dl=tb&rsv_enter=0&rsv_btype=t&rsv_jmp=slow F12 stay console Enter the following two lines of code in the tab :
const getUrlParam = a => (a = location.search.substr(1).match(new RegExp(`(^|&)${a}=([^&]*)(&|$)`)),a?a[2]:null);
const getUrlParams = url => {let reg = /([^=&\s]+)[=\s]*([^&\s]*)/g, ls = url || location.search.substr(1), obj = {};while (reg.exec(ls)) obj[RegExp.$1] = decodeURIComponent(RegExp.$2);return obj;};Enter and run
getUrlParam('wd')
decodeURIComponent(getUrlParam('wd'))
getUrlParams()
Show the following

In one case, if it is used vue perhaps Angular Framework of the hash Pattern routing
Just use the above getUrlParam and getUrlParams Method cannot get url? hinder queryparams Parameter contents
Need to be right getUrlParam and getUrlParams Two methods are simple refactoring , The code is modified as follows , You can fit vue or Angular The framework
const getUrlParam = a => (a = (location.search?location.search.substr(1):(location.hash.split('?')[1]||'')).match(new RegExp(`(^|&)${a}=([^&]*)(&|$)`)),a?a[2]:null);// compatible vue and Angular Of hash Pattern url Parameter format const getUrlParams = url => {let reg = /([^=&\s]+)[=\s]*([^&\s]*)/g, ls = url || (location.search?location.search.substr(1):(location.hash.split('?')[1]||'')), obj = {};while (reg.exec(ls)) obj[RegExp.$1] = decodeURIComponent(RegExp.$2);return obj;};// compatible vue and Angular Of hash Pattern url Parameter format The core adjustment code is (location.search?location.search.substr(1):(location.hash.split('?')[1]||''))
In this way vue or Angular Under the framework system, it is compatible to obtain the parameters of the browser address .
Of course , If you want to use vue and Angular The object provided by the framework to obtain the web browser address url Later parameters , You can also learn more through the following links
边栏推荐
- HTB-Beep
- 计算BDP值和wnd值
- Equal proportion of R language test group: use the prop.test function to test whether the success proportion of the two groups is equal
- Summary of common attributes of flex layout
- [typescript manual]
- VPP不能加载UP状态接口
- Unity accesses chartandgraph chart plug-in
- 聊聊 Redis 是如何进行请求处理
- The difference between function and task in SystemVerilog
- background
猜你喜欢

Adaptation dynamics | in June, sequoiadb completed mutual certification with five products

The selection reference of Junzheng T41, T40 and T31 versions are all here

50:第五章:开发admin管理服务:3:开发【查询admin用户名是否已存在,接口】;(这个接口需要登录时才能调用;所以我们编写了拦截器,让其拦截请求,判断用户是否是登录状态;)

Programming hodgepodge (II)

JWT(json web token)

Single sign on (one sign on, available everywhere)

微服务 - 网关Gateway组件
![Atof(), atoi(), atol() functions [detailed]](/img/5a/a421eab897061c61467c272f122202.jpg)
Atof(), atoi(), atol() functions [detailed]

HTB-Devel

FinClip实现微信授权登录的三种方案
随机推荐
剑指offer专项突击版第9天
线性代数(三)
HTB-Beep
Introduction summary of using unirx in unity
How to carry out the function test with simple appearance and complex interior?
Array programming problem of CSDN programming challenge
LeetCode 15:三数之和
Automatic usage in SystemVerilog
Summary of common attributes of flex layout
What content does the software test plan include and how to write it. Share test plan template
编程大杂烩(一)
Leetcode 202. happy number (not happy at all)
LeetCode第302场周赛
ZTE's first 5g mobile phone, axon 10 pro, was launched in the first half of this year
HTB-Arctic
MATLAB作图实例:5:双轴图
What should testers do if they encounter a bug that is difficult to reproduce?
Interface idempotency
Vim配置Golang开发环境
批量下载视频小技巧
https://router.vuejs.org/zh/api/index.html#component-injections