vue.js这个。$ route.params总是空的

时间:2018-01-25 13:58:04

标签: vue.js vue-router

这是我的router.js

export default new VueRouter({
    mode: 'history',

    routes: [
        {path: '/:mid', component: load('views/main'), meta: {name: 'Main'}},
        {path: '/:mid/auth/:uid', component: load('views/auth'), meta: {name: 'Login'}},
        {path: '/:mid/success', component: load('views/success'), meta: {name: 'LoginSuccess'}},
        ....
    ]
})

这是main.js

Quasar.start(() => {
    new Vue({
        el: '#q-app',
        created() {
            console.log(this.$route.params)
        },
        router,
        store,
        render: h => h(require('./App'))
    })
})

当我访问localhost:8080 / abc / auth / 123时,控制台显示{}而不是{mid:'abc',uid:123}。

有什么想法吗?

======更新==

console.log(this)显示了这个:

Vue$2 {_uid: 3, _isVue: true, $options: {…}, _renderProxy: Proxy, _self: Vue$2, …}
$children:[VueComponent]
$createElement:ƒ (a, b, c, d)
$el:div#q-app
...(too many lines)

console.log(此。$ route)显示:

{name: null, meta: {…}, path: "/", hash: "", query: {…}, …}
fullPath:"/"
hash:""
matched:[]
meta:{}
name:null
params:{}
path:"/"
query:{}
__proto__:Object

1 个答案:

答案 0 :(得分:0)

尝试使用功能模式将参数传递给您的路线。 https://router.vuejs.org/en/essentials/passing-props.html