VueJs 获取 url 查询 [英] VueJs get url query
问题描述
我正在用 vuejs 开发一个网站,此时我遇到了麻烦,我需要从像这样 websitename.com/user/?page=1 这样的 url 中获取 url 查询(页面),但是 this.$router.query.page
给了我一个错误(Uncaught TypeError: Cannot read property 'page' of undefined)
I'm developing a website with vuejs and at this moment I'm in trouble, I need to get the url query (page) from a url like this websitename.com/user/?page=1 but the this.$router.query.page
gives me an error (Uncaught TypeError: Cannot read property 'page' of undefined)
有人知道这个问题并且可以帮助我吗?
Does someone know something about this problem and can help me?
PS:我可以使用
this.$router.push({name: 'userIndex', query: { page: '123' } });
我可以得到像
userID -> (websitename.com/user/:userId | websitename.com/user/1)
但我无法获取任何查询参数.
but I can't get any query parameter.
推荐答案
我认为你可以像这样简单地调用,这会给你结果值.
I think you can simple call like this, this will give you result value.
this.$route.query.page
看图片 $route 是 Vue 实例中的对象,您可以使用此关键字访问,然后您可以选择上面的对象属性:
Look image $route is object in Vue Instance and you can access with this keyword and next you can select object properties like above one :
查看用于选择查询值的 Vue-router 文档:
Have a look Vue-router document for selecting queries value :
这篇关于VueJs 获取 url 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!