如何在 vuejs 中获取 http 引用? [英] How to get http refere in vuejs?
问题描述
我想在我的页面中获取用户来自哪个页面.
I would like to get from which page a user came from in my page.
目前,我想在我的 created() 或mounted() 页面中获取此信息.使用 this.$router 或 this.$route 但它们都不包含此信息.
Currently, I would like to get this info in my created() or mounted() pages. Using this.$router or this.$route but none of them contain this info.
我知道在导航守卫中,我们可以使用这个:
I know in the navigation guards, we can use this :
router.beforeEach((to, from, next) => { })
要知道页面来自哪里,但我不想使用 router.beforeEach 因为它在我的 main.js 中找到,但我想获取引用的位置在我的组件页面中,无论是在 created/挂载方法
to know where the page is comming from, but I don't want to use router.beforeEach because that is in found inside my main.js but where I want to get the referer is in my components page, either in created/mounted methods
这可能吗?
推荐答案
你可以在 App.vue 中的mounted()钩子中使用this.$route.query
.你不需要router.beforeEach,因为它没有意义.App.vue 挂载一次,当应用加载时,这是检查路由器查询参数的好地方.
You can use this.$route.query
in mounted() hook in App.vue. You don't need router.beforeEach, because it dosn't make sense. App.vue mounted one time, when app is loaded, so this a good place to check router query params.
这篇关于如何在 vuejs 中获取 http 引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!