简体   繁体   English

如何使用Vue js从URL获取参数

[英]How do I get parameters from URL using Vue js

I have URL adresses like this: 我有这样的网址地址:

http:://www.mywebsite.com/myapp?brand=nameOfBrand&user=0123456&type=comm HTTP :: //www.mywebsite.com/myapp?品牌= nameOfBrand与用户= 0123456&类型= COMM

I have to use that info to show the logo of 'nameOfBrand'. 我必须使用该信息来显示“ nameOfBrand”的徽标。 So if I get brand=google , the logo of Google will appear, if I get brand=Amazon , the logo of Amazon appears, and so on... 因此,如果我获得brand=google ,则将显示Google的徽标,如果我获得brand=Amazon ,则将显示brand=Amazon的徽标,依此类推...

Do you know how I can get this parameter? 您知道我如何获得该参数吗?

 var url_string = "http://www.mywebsite.com/myapp?brand=nameOfBrand&user=0123456&type=comm"; //window.location.href var url = new URL(url_string); var brand = url.searchParams.get("brand"); console.log(brand); 

You can use URL to convert it and using searchParams.get method to grab the particular value that you want. 您可以使用URL进行转换,也可以使用searchParams.get方法获取所需的特定值。

For more information 欲了解更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM