我正在尝试获取根路由中的GET参数。我从文档中读到,我需要_id.vue文件来做这件事,我把它放在和'index.vue‘相同的级别。在index.vue中,我有:
beforeMount () {
console.log(this.$route);
}我正在尝试使用URL中的params来访问它,但this.$route.params为空。
发布于 2019-04-16 09:11:57
你在把各种东西混在一起。this.$route.params用于路由参数,例如_id.vue。例如,假设你有pages/some/_id.vue,然后你加载url /some/param/,在你的$route.params中将是id:param。
但是如果你想获得GET参数,比如/some?param=value,你就不需要_id了。它只是通过this.$route.query访问的
请在此处查看docs
发布于 2019-04-16 06:30:30
JavaScript方式:
const urlParams = new URLSearchParams(window.location.search);
const id = urlParams.get('id'); // ?id=123https://stackoverflow.com/questions/55696178
复制相似问题