vue 獲取url參數(shù)、get參數(shù)返回?cái)?shù)組的操作
這是vue過(guò)濾器 獲取url參數(shù),返回?cái)?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;};
補(bǔ)充知識(shí):vue中使用getUrlParam()方法來(lái)獲取URL的值
首先建一個(gè)GetUrlParam.js,然后在需要的頁(yè)面中引入使用:
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ù)返回?cái)?shù)組的操作就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. Jsp中request的3個(gè)基礎(chǔ)實(shí)踐2. Django程序的優(yōu)化技巧3. XML入門(mén)的常見(jiàn)問(wèn)題(一)4. IntelliJ IDEA 統(tǒng)一設(shè)置編碼為utf-8編碼的實(shí)現(xiàn)5. jsp EL表達(dá)式詳解6. Django ORM實(shí)現(xiàn)按天獲取數(shù)據(jù)去重求和例子7. chat.asp聊天程序的編寫(xiě)方法8. Python多線程操作之互斥鎖、遞歸鎖、信號(hào)量、事件實(shí)例詳解9. idea設(shè)置自動(dòng)導(dǎo)入依賴的方法步驟10. 怎樣才能用js生成xmldom對(duì)象,并且在firefox中也實(shí)現(xiàn)xml數(shù)據(jù)島?
