vue component subassembly to pass by value Parent

Subassembly:

< Template > < div class = "App" > < INPUT @click = "SENDMSG" type = "Button" value = "parent element to pass a value" > </ div > </ Template > < Script > 
Export default { 
    Data ( ) { return {
             // the parent element to pass msg             msg: " I am subassembly msg " , 
        } 
    }, 
     Methods: { 
         SENDMSG () { //
    
       
    


 
        

             func: a function of the transmitted data binding component designated parent, this.msg: parent component subassembly to pass data 
             the this . $ EMIT ( ' FUNC ' , the this a .msg) 
         } 
     } 
} 
</ Script >

Subassembly pass a value to the parent component through this. $ Emit () manner

Note: func function name here is the parent component in binding

Parent component:

<template>
    <div class="app">
        <child @func="getMsgFormSon"></child>
    </div>
</template>
<script>
import child from './child.vue'
export default {
    data () {
        return {
            msgFormSon: "this is msg"
        }
    },
    components:{
        child,
    },
    methods:{
            getMsgFormSon(data){
                this.msgFormSon = data
                console.log(this.msgFormSon)
            }
    }
}
</script>

 

Guess you like

Origin www.cnblogs.com/Hajar/p/11128116.html