<template>
    <div id="index">
        <h1>this is index</h1>
        <my-header></my-header>   

    </div>
</template>

<script>
    import myHeader from './header'
    export default{
        components:{
            myHeader
        },
        data(){
            return {
                msg:'this is index message'
            }
        },
        methods:{
           fun(){
               console.log("这是一个父组件方法")
           }
        }
    }
</script>

<template>
    <div id='header'>
        <h1>this is header</h1>
        <button @click="getAttr">获取父组件属性方法</button>
    </div>
</template>
<script>
    export default{
        data(){
            return {
                
            }
        },
        methods:{
             getAttr(){
                 console.log(this.$parent.msg);
                 this.$parent.fun();
             }
        }
    }
</script>

Logo

前往低代码交流专区

更多推荐