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ù)名1 let model = getUrlParam(“model”); //參數(shù)名2 console.log( id ) console.log( model )
以上這篇vue 獲取url參數(shù)、get參數(shù)返回數(shù)組的操作就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Vue報錯:Injection?"xxxx"?not?found的解決辦法
這篇文章主要給大家介紹了關(guān)于Vue報錯:Injection?"xxxx"?not?found的解決辦法,文中通過圖文將解決的辦法介紹的非常詳細(xì),對大家的學(xué)習(xí)具有一定的參考借鑒價值,需要的朋友可以參考下2023-07-07利用vue3自己實現(xiàn)計數(shù)功能組件封裝實例
組件(Component) 是Vue.js最強大的功能之一,組件可以擴展 HTML 元素,封裝可重用的代碼,這篇文章主要給大家介紹了關(guān)于利用vue3自己實現(xiàn)計數(shù)功能組件封裝的相關(guān)資料,需要的朋友可以參考下2021-09-09vue3編譯報錯ESLint:defineProps is not defined&nbs
這篇文章主要介紹了vue3編譯報錯ESLint:defineProps is not defined no-undef的問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-03-03