Last active
January 28, 2025 09:45
-
-
Save JeffreyWay/85334bdc957b37a45a75c542c19cd710 to your computer and use it in GitHub Desktop.
Learn Vue 3: Step By Step, Episode 28 - Build a Modal Component - https://laracasts.com/series/learn-vue-3-step-by-step/episodes/28
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 setup> | |
defineProps({ | |
show: Boolean | |
}); | |
</script> | |
<template> | |
<div v-if="show" class="modal-mask"> | |
<div class="modal-container"> | |
<div> | |
<slot>default body</slot> | |
</div> | |
<footer class="modal-footer"> | |
<slot name="footer"> | |
<button @click="$emit('close')">Close</button> | |
</slot> | |
</footer> | |
</div> | |
</div> | |
</template> | |
<style> | |
.modal-mask { | |
position: fixed; | |
inset: 0; | |
background: rgba(0, 0, 0, .6); | |
display: grid; | |
place-items: center; | |
} | |
.modal-container { | |
background: white; | |
padding: 1rem; | |
width: 80vw; | |
max-width: 500px; | |
border-radius: 7px; | |
} | |
.modal-footer { | |
border-top: 1px solid #ddd; | |
margin-top: 1rem; | |
padding-top: 0.5rem; | |
font-size: .8rem; | |
} | |
.modal-footer button { | |
background: #ddd; | |
padding: .25rem .75rem; | |
border-radius: 20px; | |
} | |
.modal-footer button:hover { | |
background: #c8c8c8; | |
} | |
</style> |
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 setup> | |
import TeamHeader from "@/components/Teams/TeamHeader.vue"; | |
import TeamMembers from "@/components/Teams/TeamMembers.vue"; | |
import TeamFooter from "@/components/Teams/TeamFooter.vue"; | |
import { useTeamStore } from "@/stores/TeamStore"; | |
import Modal from "@/components/Modal.vue"; | |
import { ref } from "vue"; | |
let team = useTeamStore(); | |
team.fill(); | |
let showModal = ref(false); | |
</script> | |
<template> | |
<TeamHeader @add="showModal = true" /> | |
<div class="place-self-center flex flex-col gap-y-3" style="width: 725px"> | |
<TeamMembers /> | |
</div> | |
<TeamFooter /> | |
<Modal :show="showModal" @close="showModal = false"> | |
<template #default> | |
<p>Need to add a new member to your team?</p> | |
<form class="mt-6"> | |
<div class="flex gap-2"> | |
<input type="email" placeholder="Email Address..." class="flex-1"> | |
<button>Add</button> | |
</div> | |
</form> | |
</template> | |
</Modal> | |
</template> |
If teams data or member data is not access in component.
Then this is fix, TeamHeader.vue. [Not the best Way]
`<script setup>
import {useTeamStore} from "@/stores/TeamStore";
// Import your Pinia store
// Use the Pinia store to access state
const teamStore = useTeamStore();
</script>`
//user
:disabled="teamStore.members.length === teamStore.spots"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
HI everyone.
If the button is not clickable.. TeamHeader.vue file.
@click="this.$emit('add')"> Add Member