S
S
Serge9991112021-09-27 08:41:12
Vue.js
Serge999111, 2021-09-27 08:41:12

Can't figure out how to pass a parameter to vue.js from a component to a parent or another component?

I have a Navigation component.

How can I make sure that when I click on the button, in this Navigation component I have a parameter (a numeric value in data) passed to the parent app.vue component?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Gennady, 2021-09-27
@Serge999111

Raise the $emit event from child to parent components.
For example:

// дочерний компонент your-component
...
methods: {
  doSomething() {
    this.$emit('yourEvent', {
      params: this.params,
    })
  }
}

// родительский компонент
<template>
  <your-component :someProps="parent" @yourEvent="doSomething" />
</template>
...
methods: {
  doSomething(data) {
    // какой-то код
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question