vue中獲取url參數


1、路由獲取

this.delivery_asn = this.$route.query.delivery_asn;

2、非路由獲取

(1)在js文件中寫方法

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

}

(2)在項目文件中引入

     import { getUrlKey } from '@/utils';

(3)在項目文件中使用

  this.delivery_asn  = getUrlKey("delivery_asn ",window.location.href)

 

 

 如果url中參數base64編碼

  let path = window.location.href.split("?") //分割url
  let href = path[0]+"?"+path[1]
  let query = Base64.decode(path[1])  //解碼
  href = path[0]+"?"+ query //解碼后重組

  this.delivery_asn  = getUrlKey("delivery_asn ",href)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM