vue 獲取url參數(shù)、get參數(shù)返回數(shù)組的操作
這是vue過濾器 獲取url參數(shù),返回數(shù)組
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}
引用
import { getUrlParam } from “…/components/GetUrlParam”;
使用:
let id = getQueryString(“ryid”); //參數(shù)名1let model = getUrlParam(“model”); //參數(shù)名2console.log( id )console.log( model )
以上這篇vue 獲取url參數(shù)、get參數(shù)返回數(shù)組的操作就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。
相關文章:
1. vue3?Error:Unknown?variable?dynamic?import:?../views/的解決方案2. CSS代碼檢查工具stylelint的使用方法詳解3. Python 多線程之threading 模塊的使用4. python求numpy中array按列非零元素的平均值案例5. python利用platform模塊獲取系統(tǒng)信息6. python 實現(xiàn)rolling和apply函數(shù)的向下取值操作7. react axios 跨域訪問一個或多個域名問題8. python OpenCV學習筆記9. WML語言的基本情況10. Python的Tqdm模塊實現(xiàn)進度條配置
