A
A
Anton Yurzanov2019-03-19 12:57:38
Vue.js
Anton Yurzanov, 2019-03-19 12:57:38

Vue Router how to pass variable?

Guys please help.
When you click on the link, another component opens, an id is passed to it through the route, a url of the form:
/adres/ID is formed,
everything is as it should be.
but it is required to pass one more parameter to this component, so that the component can write it to a variable, it does not work out in any way, there is not enough experience.

<router-link
                               tag="a"
                               class="button"
                               :to="{name: 'historyId', params: {id: historyItem.id, date: historyItem.date}, props: {id: historyItem.id, date: historyItem.date}}"
                               :key="historyItem.id"
                       >
                           <span class="button__icon">
                               <i class="fas fa-sync-alt"></i>
                           </span>
                           <span class="button__text">
                               Повторить
                           </span>
                       </router-link>

I'm trying to get in the component: but it doesn't work, what should I do?
date: this.$router.currentRoute.params['date'],

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Yurzanov, 2019-03-19
@ar6uz

and how to do it:
1. you need to set the permission to transfer props (props: true) in the route:

{
      path: '/history/:id',
      component: HistoryId,
      name: 'historyId',
      props: true
    }

2. specify in the route-link what parameters you want to pass (params: {}):
<router-link
                               tag="a"
                               class="button"
                               :to="{name: 'historyId', params: {id: historyItem.id, date: historyItem.date}}"
                       >

3/ Accept this data in the component:
<script>
    export default {
        props: ['date'],

R
Roman Alekseiev, 2019-03-19
@zorar4ik

Passing input parameters

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question