ImageModal v-model

This commit is contained in:
Jörn-Michael Miehe 2022-10-30 03:04:25 +00:00
parent b6deb22cc8
commit cf318212ba
3 changed files with 18 additions and 20 deletions

View file

@ -6,20 +6,16 @@
<CalendarDoor v-for="(_, index) in 24" :key="index" :day="index" /> <CalendarDoor v-for="(_, index) in 24" :key="index" :day="index" />
</div> </div>
<ImageModal />
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts">
import { Options, Vue } from "vue-class-component"; import { Options, Vue } from "vue-class-component";
import CalendarDoor from "./components/CalendarDoor.vue"; import CalendarDoor from "./components/CalendarDoor.vue";
import ImageModal from "./components/ImageModal.vue";
@Options({ @Options({
components: { components: {
CalendarDoor, CalendarDoor,
ImageModal,
}, },
}) })
export default class App extends Vue {} export default class App extends Vue {}

View file

@ -1,23 +1,26 @@
<template> <template>
<a <ImageModal v-model="modal_visible" />
class="button"
:href="'http://localhost:8000/api/days/picture/' + day" <button class="button" @click="modal_visible = true">
target="_blank"
>
Türken {{ day + 1 }} Türken {{ day + 1 }}
</a> </button>
</template> </template>
<script lang="ts"> <script lang="ts">
import { Vue, Options } from "vue-class-component"; import { Vue, Options } from "vue-class-component";
import ImageModal from "./ImageModal.vue";
@Options({ @Options({
components: {
ImageModal,
},
props: { props: {
day: Number, day: Number,
}, },
}) })
export default class CalendarDoor extends Vue { export default class CalendarDoor extends Vue {
day!: number; day!: number;
modal_visible = false;
} }
</script> </script>

View file

@ -1,5 +1,5 @@
<template> <template>
<div class="modal is-active" v-if="visible" @click="hide"> <div class="modal is-active" v-if="modelValue" @click="hide">
<div class="modal-background" /> <div class="modal-background" />
<div class="modal-content"> <div class="modal-content">
@ -8,15 +8,18 @@
<!-- </p> --> <!-- </p> -->
</div> </div>
</div> </div>
<button class="button" @click="show">modal</button>
</template> </template>
<script lang="ts"> <script lang="ts">
import { Vue } from "vue-class-component"; import { Options, Vue } from "vue-class-component";
@Options({
props: {
modelValue: Boolean,
},
})
export default class ImageModal extends Vue { export default class ImageModal extends Vue {
visible = false; modelValue!: boolean;
public created(): void { public created(): void {
window.addEventListener("keydown", (e) => { window.addEventListener("keydown", (e) => {
@ -24,12 +27,8 @@ export default class ImageModal extends Vue {
}); });
} }
private show(): void {
this.visible = true;
}
private hide(): void { private hide(): void {
this.visible = false; this.$emit("update:modelValue", false);
} }
} }
</script> </script>