vue.js (19) - vue neutron component invokes the parent component method

Sub-assembly method can not be used directly in the parent component, the need for event binding (v-on: a custom method name = "parent component method name"), and then define a method in the sub-components, the use of this $. EMIT ( 'custom method name') statement completion method to call the parent component subassembly, the subassembly last method may be called directly defined.

< Div class = "App" > 
        < MYCOM v-on: FUNC = "parentshow" > </ MYCOM > 
        <-! By v-on: a method of binding methods parent components bound to func, 
            then the sub- component defining a method (this $ emit ( 'func' ).) the sub-assembly is transmitted to func, 
            this subassembly can call the method through their parent component process -> 
    </ div > 
    < Template ID = " cmp " > 
        < div > 
            < A href =" # " @ click.prevent =" Show " > Come I </ A > 
        </div>
    </template>
    < Script > 
        var VM =  new new Vue ({ 
        EL: ' .app ' , 
        Data: { 
            MSG: ' I is a process for the parent element ' 
        }, 
        Methods: { 
            parentshow () { 
                Alert ( the this a .msg) 
            } 
        }, 
        Components: { 
            MYCOM: { 
                Template: ' #cmp ' , 
                Methods: { 
                    Show () { 
                        the this . $ EMIT ( ' FUNC' ) // This method of establishing the method to call methods subassembly parent components 
                    } 
                } 
            } 
        } 
    })   
    </ Script >

 

Guess you like

Origin www.cnblogs.com/qiqisusu/p/11372950.html