如何在vuejs中读取URL查询参数值 [英] How to read URL query param value in vuejs
问题描述
在 vuejs 回调 URL 中,我有一些参数值,我需要读取这个参数值.例如返回 url 是:http://localhost:8080/#/sucesspage?encryteddata=abdeshfkkilkalidfel&9a
In vuejs callback URL I've some parameter value and I need to read this param value. For example the return url is: http://localhost:8080/#/sucesspage?encryteddata=abdeshfkkilkalidfel&9a
我已经尝试过 this.$route.query.encryteddata
但我得到的是空值.
I have tried this.$route.query.encryteddata
but I'm got null value.
vuejs 有没有办法获取param值?
Is there any way to get the param value in vuejs?
推荐答案
你应该明白 Vue 中的路由查询和路由参数是两个不同的东西.您在路由器中声明路由参数,例如 www.example.com/30
= /:id
,然后您可以通过 this.$route 获取该数据.params.id
You should understand that Route Querys and Route Params in Vue are 2 different things. You declare Route params in your Router for example www.example.com/30
= /:id
, then you can get that data via this.$route.params.id
Url 查询通常看起来像 www.example.com/hello?visible=false
,您可以使用
The Url Querys usually look like www.example.com/hello?visible=false
and you can grab those with
let urlParams = new URLSearchParams(window.location.search);
let myParam = urlParams.get('visible');
您还可以将这 2 项组合起来,例如获取 ID 为 30
的文章,同时让查询告诉您一些其他附加信息./30?visible=false
You can also combine these 2 for example getting on the Article with the ID of 30
while having a query telling you some other additional info. /30?visible=false
这篇关于如何在vuejs中读取URL查询参数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!