<template>
    <div id="index">
        <h1>this is index</h1>
        <my-header ref='header'></my-header>   
        <button @click='attack'>触发子组件方法</button>
    </div>
</template>

<script>
    import myHeader from './header'
    export default{
        components:{
            myHeader
        },
        data(){
            return {
            }
        },
        methods:{
            attack(){
                console.log(this.$refs.header.msg);
                this.$refs.header.fun();
            }
        }
    }
</script>

<template>
    <div id='header'>
        <h1>this is header</h1>
    </div>
</template>
<script>
    export default{
        data(){
            return {
                msg:'this is header message'
            }
        },
        methods:{
             fun(){
                 console.log('this is header');
             }
        }
    }
</script>

Logo

前往低代码交流专区

更多推荐