How to pass url parameters to Vuejs

后端 未结 5 2012
感情败类
感情败类 2021-02-13 05:14

I\'m building an app with laravel and VueJs and I was wondering how to pass a url parameter like the user slug or the user id to vuejs in a proper way to be able to use that pa

5条回答
  •  梦如初夏
    2021-02-13 05:45

    vue-router would probably be of help here. It lets you define your routes like so:

    router.map({
        '/user/:slug': {
            component: Profile,
            name: 'profile'
        },
    })
    

    Within your Profile component, the requested user's slug would then become available under this.$route.params.slug

    Check the official documentation for details: http://router.vuejs.org/en/

提交回复
热议问题