当前位置:网站首页>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
边栏推荐
- Terminate 5g chip cooperation! The official response of Intel and zhanrui came
- Microservice - hystrix fuse
- easyrecovery免费数据恢复工具操作简单一键恢复数据
- systemVerilog中automatic用法
- HTB-Beep
- Introduction to interface in SystemVerilog
- Oracle 用户A删除用户B名下的一张表后,用户B可以通过回收站恢复被删除的表吗?
- After Oracle user a deletes a table under user B's name, can user B recover the deleted table through the recycle bin?
- Detailed explanation of stepn chain game system development mode (Sports money making mode)
- Exchange 2010 SSL certificate installation document
猜你喜欢

Microservice gateway component

Programming hodgepodge (II)

FinClip实现微信授权登录的三种方案

Leetcode 204. 计数质数(太妙了)

线性代数(三)

systemverilog中function和task区别

What content does the software test plan include and how to write it. Share test plan template

Game 302 of leetcode

Realsense d435i depth map optimization_ High precision mode

HTB-Granpa
随机推荐
Array programming problem of CSDN programming challenge
MATLAB作图实例:5:双轴图
JWT(json web token)
Detailed explanation of stepn chain game system development mode (Sports money making mode)
Microservices and related component concepts
Leetcode 237. 删除链表中的节点
Tips for downloading videos in batches
2020icpc Jiangxi warm up e.robot sends red packets (DFS)
The global shipment of glory 8x series exceeded 10million units, and the glory V20 exceeded 1.5 million units!
The selection reference of Junzheng T41, T40 and T31 versions are all here
动态规划学习笔记
Obj file format and.Mtl file format
Talk about how redis handles requests
新时代生产力工具——FlowUs 息流全方位评测
接口幂等性
Microservice gateway component
Microservice - hystrix fuse
Three schemes for finclip to realize wechat authorized login
For data security reasons, the Dutch Ministry of Education asked schools to suspend the use of Chrome browser
Leetcode 204. 计数质数(太妙了)
https://router.vuejs.org/zh/api/index.html#component-injections