例:父组件调用窗口子组件


父组件

<dialog :is-show="isShowDialog" @on-close="closeDialog">
    
</dialog>

<script>
    data () {
        return {
            isShowDialog: false
        }       
    },
    method: {
        closeDialog () {
            this.isShowDialog = false
        }
</script>

子组件

<div v-if="isShow">
    <div @click="closeMyself">
    </div>
    <div>
        <p @click="closeMyself">
        </p>
    </div>
</div>

<script>

export default {
    props: {
        isShow: {
            type: Boolean,
            default: false
        }
    },
    methods: {
        closeMyself () {
            this.$emit('on-close')
        }
    }
}
</script>

关注公众号"阿里亲学长",更快获取前端知识

Logo

前往低代码交流专区

更多推荐