Created
June 13, 2021 13:06
-
-
Save ejirocodes/a262e9b82906b5e50d9981acc3d72031 to your computer and use it in GitHub Desktop.
Vue: Passing data from child to parent component - Emit
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
<script> | |
export default { | |
data() { | |
return { | |
loginModalState: null, | |
isDisabled: false, | |
}; | |
}, | |
props: { | |
isOpen: { | |
typeof: Boolean, | |
required: true, | |
}, | |
}, | |
computed: { | |
login() { | |
return this.$store.state.login.isLoginOpen; | |
}, | |
isLoginModalOpen: { | |
get: function () { | |
return this.isOpen; | |
}, | |
set: function (newValue) { | |
this.loginModalState = newValue; | |
return newValue; | |
}, | |
}, | |
}, | |
methods: { | |
closeModal() { | |
this.isLoginModalOpen = false; | |
this.$emit("getLoginModalState", this.loginModalState); | |
}, | |
}, | |
}; | |
</script> |
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
<template> | |
<Login | |
:isOpen="isOpenLoginModal" | |
@getLoginModalState="updateLoginModalState($event)" | |
/> | |
<Signup | |
:isOpen="isOpenSignupModal" | |
@getSignupModalState="updateSignupModalState($event)" | |
/> | |
</template> | |
<script> | |
export default { | |
data() { | |
return { | |
isOpenLoginModal: false, | |
isOpenSignupModal: false, | |
}; | |
}, | |
methods: { | |
// Receive close and open modal state from log in component | |
updateLoginModalState(openState) { | |
this.isOpenLoginModal = openState; | |
}, | |
// Open Login in modal | |
openLoginModal() { | |
this.isOpenLoginModal = true; | |
}, | |
// Open Sign up modal | |
openSignupModal() { | |
this.isOpenSignupModal = true; | |
}, | |
// Receive close and open modal state from signup component | |
updateSignupModalState(openState) { | |
this.isOpenSignupModal = openState; | |
} | |
} | |
}; | |
</script> | |
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
<script> | |
export default { | |
data() { | |
return { | |
signupModalState: null, | |
isDisabled: false, | |
}; | |
}, | |
props: { | |
isOpen: { | |
typeof: Boolean, | |
required: true, | |
}, | |
}, | |
computed: { | |
isModalOpen: { | |
get: function () { | |
return this.isOpen; | |
}, | |
set: function (newValue) { | |
this.signupModalState = newValue; | |
return newValue; | |
}, | |
}, | |
}, | |
methods: { | |
closeModal() { | |
this.isModalOpen = false; | |
this.$emit("getSignupModalState", this.signupModalState); | |
}, | |
}, | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment