当前位置:网站首页>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
边栏推荐
- 50: Chapter 5: develop admin management service: 3: develop [query whether the admin user name already exists, interface]; (this interface can only be called when logging in; so we have written an int
- 2020ICPC 江西省赛热身赛 E.Robot Sends Red Packets(dfs)
- VPP不能加载UP状态接口
- Leetcode 237. delete nodes in the linked list
- C Programming -- the solution of dynamic programming of "the sum of the largest subarray"
- Microservice configuration center Nacos
- An SQL execution process
- uniapp手机端uView的u-collapse组件高度init
- flex布局常用属性总结
- Openfegin remote call lost request header problem
猜你喜欢
随机推荐
LCP plug-in creates peer-to-peer 802.1ad interface
Differences and application directions of GPS, base station and IP positioning
Flexible layout summary
Three schemes for finclip to realize wechat authorized login
Leetcode 204. 计数质数(太妙了)
The difference between $write and $display in SystemVerilog
C Programming -- the solution of dynamic programming of "the sum of the largest subarray"
Introduction summary of using unirx in unity
动态规划学习笔记
Arm PWN basic tutorial
SystemVerilog中interface(接口)介绍
Detailed explanation of stepn chain game system development mode (Sports money making mode)
Talk about how redis handles requests
The price is 17300! Why does Huawei mate x face Samsung fold?
Run length test of R language: use the runs.test function to perform run length test on binary sequence data (check whether the sequence is random)
VPP不能加载UP状态接口
The u-collapse component of uniapp mobile uview is highly init
Leetcode 15: sum of three numbers
Automatic usage in SystemVerilog
新时代生产力工具——FlowUs 息流全方位评测
https://router.vuejs.org/zh/api/index.html#component-injections







