A
A
AleDv2021-07-08 09:00:49
Vue.js
AleDv, 2021-07-08 09:00:49

How to pass parameter from router to child component on page load?

Hello. There is a parent component, which hosts a child component, to which you need to pass a parameter from the current url (vue-router).

<template>
<favorite-button :userid="userid"/>
</template>
...
<script>
...
mounted() {
    this.userid = this.$route.params.id;
}
...
</script>


The problem is that when the parent component is loaded, undefined arrives in the favorite-button instead of the id specified in the url.

How to fix this problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin B., 2021-07-08
@Kostik_1993

You can't use this inside a component template this time. The second is that the id attribute is an html attribute and cannot be used as props, replace it with route-id for example.
In general, this transfer is meaningless, since you can get the parameter inside

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question