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
If you are using vue-router and want to capture query parameters and pass them to props, you can do it this way.
Url being called : http://localhost:8080/#/?prop1=test1&prop2=test2
MyComponent.vue
{{prop1}} {{prop2}}
router/index.js
import Vue from 'vue'
import Router from 'vue-router'
import MyComponent from '@/components/MyComponent'
Vue.use (Router)
Vue.component ('my-component', MyComponent)
export default new Router ({
routes: [
{
path: '/',
name: 'MyComponent',
component: MyComponent,
props: (route) => ({
prop1: route.query.prop1,
prop2: route.query.prop2
})
}
]
})