@gage Используйте $emit() чтобы передать данные обратно родителю в Vue.js и ниже небольшой пример кода:
Родительский компонтент:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<template> <div class="container"> <h1>Тестовый компонент</h1> <p>{{ text }}</p> <child @update-text="updateText" /> </div> </template> <script> import Child from '@/components/Child' export default { name: 'Test', components: { Child }, data() { return { text: '', } }, methods: { updateText(text) { this.text = text }, }, } </script> |
Дочерний компонент:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<template> <div class="wrapper"> <button @click="passToParent">Передать данные родителю</button> </div> </template> <script> export default { name: 'Child', methods: { passToParent() { this.$emit('update-text', 'привет из родителя') }, }, } </script> |