S
S
Spoon in the brain2019-11-14 19:36:05
Vue.js
Spoon in the brain, 2019-11-14 19:36:05

URL:ID VueJS how does it work?

Hello! I can't figure out how the PUT route works in VueJS.
I'll give an example:

routes: [
    { path: '/user/:id', component: User }
//Не могу понять откуда берётся id, то есть я понимаю что
//его нужно получить от бекенда, но что с ним дальше делать?
  ]

Let's say I have an id and a page of some user, (all data on this page will be obtained using id) I need to go to his page and get all the data from the name to the last post on the wall, but how to write this id into the router itself?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2019-11-14
@vessels

Use router-link to generate links containing id

<router-link :to="{ name: 'userProfile', params: { id: user.id } }">
  {{ user.name }}
</router-link>

The route must be named (parameter name):
{
      path: '/user/:id',
      name: 'userProfile',
      component: User,
    },

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question