Created
July 3, 2019 07:10
-
-
Save codebender828/3ad2a64a1f8c02db63bf425455a694e0 to your computer and use it in GitHub Desktop.
How to use modal component in parent component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Parent Component --> | |
<template> | |
<div> | |
<modal :show-modal="showModal"> | |
<h1 slot="header">{{ title }}</h1> | |
<p slot="body">{{ body }}</p> | |
<div slot="footer"> | |
<base-button | |
@click.native="hideModal" | |
> | |
{{ buttonMessage ? buttonMessage : 'Okay' }} | |
</base-button> | |
</div> | |
</modal> | |
</div> | |
</template> | |
<script> | |
import Modal from '@/components/modal/modal.vue' | |
import BaseButton from '@/components/buttons/button-base.vue' | |
export default { | |
name: 'InterpreterRoot', | |
components: { | |
Modal, | |
BaseButton | |
}, | |
data() { | |
return { | |
// Passes this as prop to <modal /> component | |
showModal: false, | |
title: 'Modal title', | |
body: 'This is the modal text', | |
buttonMessage: 'Got it!' | |
}; | |
}, | |
methods: { | |
removeModal() { | |
this.showModal = false; | |
}, | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment