如何用Vue获取URL参数并返回数组形式的get参数?

2026-04-02 10:351阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计268个文字,预计阅读时间需要2分钟。

如何用Vue获取URL参数并返回数组形式的get参数?

这是Vue过滤器+获取URL参数,返回数组+Vue.prototype.$url=function() { var url=decodeURIComponent(location.search); // 获取url中?符后的字符串 var theRequest=new Object(); if (url.indexOf(?) !=-1) { var str=url.substr(url.indexOf(?) + 1); }

这是vue过滤器 获取url参数,返回数组

Vue.prototype.$url=function(){ var url = decodeURIComponent(location.search); //获取url中"?"符后的字串 var theRequest = new Object(); if (url.indexOf("?") != -1) { var str = url.substr(1); strs = str.split("&"); for(var i = 0; i < strs.length; i ++) { theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]); } } return theRequest; };

补充知识:vue中使用getUrlParam()方法来获取URL的值

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

GetUrlParam.js

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

引用

如何用Vue获取URL参数并返回数组形式的get参数?

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

使用:

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

以上这篇vue 获取url参数、get参数返回数组的操作就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。

标签:操作

本文共计268个文字,预计阅读时间需要2分钟。

如何用Vue获取URL参数并返回数组形式的get参数?

这是Vue过滤器+获取URL参数,返回数组+Vue.prototype.$url=function() { var url=decodeURIComponent(location.search); // 获取url中?符后的字符串 var theRequest=new Object(); if (url.indexOf(?) !=-1) { var str=url.substr(url.indexOf(?) + 1); }

这是vue过滤器 获取url参数,返回数组

Vue.prototype.$url=function(){ var url = decodeURIComponent(location.search); //获取url中"?"符后的字串 var theRequest = new Object(); if (url.indexOf("?") != -1) { var str = url.substr(1); strs = str.split("&"); for(var i = 0; i < strs.length; i ++) { theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]); } } return theRequest; };

补充知识:vue中使用getUrlParam()方法来获取URL的值

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

GetUrlParam.js

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

引用

如何用Vue获取URL参数并返回数组形式的get参数?

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

使用:

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

以上这篇vue 获取url参数、get参数返回数组的操作就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。

标签:操作