[Vuejs]-VueJs dynamically bind data to a route

0๐Ÿ‘

โœ…

<tbody>
      <tr v-for="paperId in QuestionPapersArray">
        <td>{{ paperId }}</td>
        <td></td>
        <th></th>
        <th><button class="btn" @click="takeExam(paperId)">Take Exam</button></th>
      </tr>
</tbody>

Try the following.

methods: {
  takeExam (paperId) {
    this.$router.push(`/startExam/${paperId}`)
  }
}  

Alternatively, you can try the following inside the takeExam() method

this.$router.push({
  path: '/startExam',
  params: {
    id: paperId
  }
})

Your route config file should be path: '/startExam/:id'

Leave a comment