首页 > 编程知识 正文

vue如何获取url参数,vue获取数据的方式

时间:2023-05-06 03:32:09 阅读:283502 作者:480

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)

 

转载于:https://www.cnblogs.com/required/p/11543652.html

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。