1

コンポーネントから $route.params.post にデータを渡そうとしていますが、どこかで失敗しており、それを機能させる方法がわかりません。

私のコンポーネントrouter-linkでは、ルートファイルの特定のパスに移動するために使用していますが、指定されたコンポーネントにルーティングしていません。

// Component.vue

<router-link :to="{ path: 'replies', params: { post: postId }}">
    <div class="button is-light is-small has-replies" @click=" postId = thread.no ">Replies</div> 
    //clicking replies will push the thread number to data and load it into the params
</router-link>

export default {
    data () {
        return {
            postId: null
        }
    }
}

// ./routes/index.js

import Replies from '../components/Replies'

routes: [
    { path: '/', component: Frontpage },
    { path: '/replies/:post', component: Replies }
]

ボタンをクリックすると、次のようなルートで Replies コンポーネントが開きますが/replies/#、空白のページが読み込まれ、コンポーネントが完全に無視されるだけです。にインポートvuex-router-syncしていますが、それが問題かどうかはわかりませんが、正しくmain.js使用しているかどうか完全に確信が持てないため、問題がある可能性があることは十分承知しています。vuex-router-sync

4

1 に答える 1

2

postIdURL パラメーターではなく、URL 自体の一部であるため、次のように試すことができます。

<router-link :to="'replies/'+ postId'">
    <div class="button is-light is-small has-replies" @click=" postId = thread.no ">Replies</div> 
    //clicking replies will push the thread number to data and load it into the params
</router-link>
于 2016-11-20T02:41:49.517 に答える