vue读取地址栏参数

news/2024/10/23 11:24:46/

vue读取地址栏参数

第一步:创建utils.js文件
export default{getUrlKey: function (name) {return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null}
}
第二步:引用文件及取值
//单文件注册
import utils from '../common/js/util.js'
//使用方式
let phone = utils.getUrlKey("userPhone")
//全局注册  在主js方法(main.js)中注册全局方法
import utils from '../common/js/util.js'    
Vue.prototype.$utils=utils   //注册全局方法
//使用方式
let phone = this.$utils.getUrlKey("userPhone")//获取url参数

url: http://XXX:XXX/#/index/?userPhone=15369457896时,可以得到userPhone为15369457896

转载: https://www.jb51.net/article/121954.htm


http://www.ppmy.cn/news/782917.html

相关文章

vue清除地址栏路由参数

方式一:覆盖 let path this.$route.path; //先获取路由路径 this.$router.push(path); //再跳转路由路径,query参数没带过去,所以被清除了方式二:(摘自评论) this.$router.push({ query: {} });方式三:使用浏览器hi…

vue怎么在地址栏隐藏路由

vue怎么在地址栏隐藏路由&#xff1a; 1.首先我们把我们要跳转的页面引入并注册&#xff1a; <script> import cate from ./goods/Cate import rights from ./power/Rights import role from ./power/Roles import user from ./user/Users export default {name: "…

chrome 隐藏 地址栏_如何在Chrome中隐藏地址栏

chrome 隐藏 地址栏 There is no easy way from within an open instance of Chrome. You need to go to the terminal and open a new Chrome instance in application mode, passing the URL. 在打开的Chrome实例中没有简单的方法。 您需要转到终端并通过URL来在应用程序模式…

地址栏中文传值,解决乱码问题

在中文加入到地址栏前&#xff0c;进行两次encodeURI转码 在传输过程中浏览器会解析一遍&#xff0c;到达指定页面获取地址栏参数的时候&#xff0c;再进行一次decodeURI解码就可以了。 发送&#xff1a;window.location.href "b.html?title"encodeURI(encodeURI…

vue3.0 路由隐藏地址栏

文章目录 一、History路由createWebHistory&#xff08;不带 # 符号&#xff0c;也不隐藏地址栏&#xff09;createMemoryHistory&#xff08;隐藏地址栏&#xff09; 二、Hash路由createWebHashHistory&#xff08;地址栏带 # 符号&#xff09; 声明一下&#xff1a;这是vue3.…

vue项目在浏览器地址栏设置图标

在vue项目中&#xff0c;我们怎样设置浏览器tab图标&#xff1f;如图 1. 我们来看vue项目的目录结构&#xff0c;根目录下有一个index.html&#xff0c;这个就相当于我们普通项目中的各个html页面文件&#xff0c;所以设置方法就是在index.html的head标签中添加link标签。 在这…

js获取地址栏中的参数

1、单个参数获取 比如url&#xff1a; http://127.0.0.1:8080/index.html?oid11000001 // 获取地址栏中的id参数var path window.location.href;var index path.lastIndexOf("?");var oid 10000000;if (index ! -1) {var params path.substring(index 1);var a…

vue:监听浏览器地址栏变化

使用watch&#xff1a; watch:{$route(to,from){console.log(to);} },