当前位置: 首页 > 工具软件 > getUrlParam > 使用案例 >

vue中使用getUrlParam()方法来获取URL的值

舒斯伯
2023-12-01

首先建一个GetUrlParam.js,然后在需要的页面中引入使用:

GetUrlParam.js

export  function getUrlParam(name) {
  return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null
}

引用

import { getUrlParam } from “…/components/GetUrlParam”;

使用:

let id = getQueryString(“ryid”); //参数名1
let model = getUrlParam(“model”); //参数名2
console.log( id )
console.log( model )

 类似资料: