vue 獲取url參數(shù)、get參數(shù)返回?cái)?shù)組的操作
這是vue過濾器 獲取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ǔ)充知識: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ù)返回?cái)?shù)組的操作就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. ASP.NET MVC獲取多級類別組合下的產(chǎn)品2. ASP.NET MVC實(shí)現(xiàn)橫向展示購物車3. ThinkPHP5 通過ajax插入圖片并實(shí)時(shí)顯示(完整代碼)4. Docker 容器健康檢查機(jī)制5. CSS3實(shí)現(xiàn)動態(tài)翻牌效果 仿百度貼吧3D翻牌一次動畫特效6. python使用openpyxl庫讀寫Excel表格的方法(增刪改查操作)7. python中asyncio異步編程學(xué)習(xí)8. python os.listdir()亂碼解決方案9. Python使用socket_TCP實(shí)現(xiàn)小文件下載功能10. ASP實(shí)現(xiàn)文件上傳的方法
