F
F
FreeBa2017-03-09 13:23:06
JavaScript
FreeBa, 2017-03-09 13:23:06

How to pass parameter from router-link to single file component in vue.js?

There is a view link

<router-link :to="{ path: '/test', query: { parameter1: 'TEST'} }">Тест</router-link>

Component reference
var router = new VueRouter({
  routes: [
    { path: '/test', component: TestComponent, props: String }
  ]
})

The component itself
<template>
  <div>{{ parameter1 }}</div> 
</template>

<script>
  module.exports = {
    props: ['parameter1'],
    created: function(){
              console.log(parameter1) //not defined
          } 
  }
</script>

Those. parameter is not passed to the component, what am I doing wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
FreeBa, 2017-03-10
@FreeBa

I did it through $route - just getting the parameters from the address bar. But I feel it's not the best solution.

S
Seraphim Topal, 2020-07-28
@no4ch

With vue-router:
link:
/link?q=value
After declaring a component, address, etc.:
props: (route) => ({ query: route.query }) - pass all incoming
props: (route) => ({ query: route.query.q }) - if we expect a specific
example in off. documentation
https://router.vuejs.org/ru/guide/essentials/passi...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question