如何从Vue.js中的URL获取查询参数? [英] How can I get query parameters from a URL in Vue.js?

查看:56
本文介绍了如何从Vue.js中的URL获取查询参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Vue.js中获取查询参数?

How can I fetch query parameters in Vue.js?

例如 http://somesite.com?test=yay .

找不到获取方法,或者我需要为此使用纯JS或某些库吗?

Can’t find a way to fetch or do I need to use pure JS or some library for this?

推荐答案

根据

According to the docs of route object, you have access to a $route object from your components, which exposes what you need. In this case

//from your component
console.log(this.$route.query.test) // outputs 'yay'

这篇关于如何从Vue.js中的URL获取查询参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆