Pass data from child to parent in Vuejs (is it so complicated?)

后端 未结 3 463
你的背包
你的背包 2020-12-01 06:28

Thanks for reading my question.

I have read about it:

vuejs update parent data from child component

https://forum.vuejs.org/t/passing-data-back-to-pa

3条回答
  •  被撕碎了的回忆
    2020-12-01 06:59

    Props are for parent -> child

    You can use $emit for child -> parent

    v-on directive captures the child components events that is emitted by $emit

    Child component triggers clicked event :

    export default {
       methods: {
         onClickButton (event) {
             this.$emit('clicked', 'someValue')
         }
       }
    }
    

    Parent component receive clicked event:

    ... export default { methods: { onClickChild (value) { console.log(value) // someValue } } }

    .

提交回复
热议问题