Vue 子组件调用父组件方法

孤街醉人 提交于 2020-04-01 07:38:46

父组件内容:

<template>
    <div>
        <info-wnd ref="infoWnd" @parentClick="wndClick"></info-wnd>
  </div>

</template>
<script>
    import infoWnd from './info-wnd';
    export default {
        data() {
            return {
            }
        },
        components: { infoWnd },
        methods: {
            wndClick() {
                   console.log('这是父组件的方法');
             }
         } 
    } 
</script>   

子组件Info-wnd.vue组件内容:

<template>
    <div @click="divClick">
        <span>这是子组件</span>
    </div>
</template>
<script>
    export default {
        data() {
            return {
            }
        },
        methods: {
            divClick() {
                this.$emit('parentClick');    //调用父组件的方法
            }
        }
    }
</script>

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!