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

查看:29
本文介绍了如何从 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?

推荐答案

根据route 对象,你可以从你的组件访问一个 $route 对象,它暴露了你需要的东西.在这种情况下

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天全站免登陆