gpt4 book ai didi

vue.js - VueRouter this.$route.query 总是空的

转载 作者:行者123 更新时间:2023-12-03 06:43:35 25 4
gpt4 key购买 nike

我正在尝试获取查询参数 code ,但是 $route.query总是空的。我根据文档使用了功能模式。有什么不见了?

路由器:

// use vue-router
import Router from 'vue-router'
Vue.use(Router)

// create router
const router = new Router({
routes: [
{
path: '/',
component: Home,
props: (route) => ({ code: route.query.code })
}
]
})

首页.vue
<template>
<div>
<Navbar />
<FlatHeader />
<v-content>
<ComingSoon />
<Changes />
<EmailSubscribe />
</v-content>
<AuthorizationModal />
</div>
</template>

<script>
import AuthorizationModal from './components/AuthorizationModal';
import FlatHeader from './components/FlatHeader';
import ComingSoon from './components/ComingSoon';
import Changes from './components/Changes';
import EmailSubscribe from './components/EmailSubscribe';

export default {
name: 'Home',
components: {
FlatHeader,
ComingSoon,
Changes,
EmailSubscribe,
AuthorizationModal
},
props: {
code: {
type: String,
default: null
}
},
methods: {
},
mounted() {
console.log(this.$route)
}
}

</script>

$route控制台输出:

enter image description here

最佳答案

我通过在 Router 上设置模式解决了这个问题到'历史'。

路由器:

// create router
const router = new Router({
mode: 'history', // add 'history' mode
routes: [
{
path: '/',
component: Home,
props: (route) => ({ code: route.query.code })
}
]
})

关于vue.js - VueRouter this.$route.query 总是空的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56309617/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com