• 카테고리

    질문 & 답변
  • 세부 분야

    프론트엔드

  • 해결 여부

    미해결

모달창 관련 질문입니다.

21.09.27 16:44 작성 조회수 313

3

- 학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요!
- 먼저 유사한 질문이 있었는지 검색해보세요.
- 서로 예의를 지키며 존중하는 문화를 만들어가요.
- 잠깐! 인프런 서비스 운영 관련 문의는 1:1 문의하기를 이용해주세요.
 
vue transition을 활용하여 강사님 강의 내용과 동일하게 Modal을 적용하였습니다.
그런데 modal창이 처음 등장할 때 애니메이션 효과는 적용되지 않네요.
강사님 코드는 다른가해서 클론받아 확인해봤는데, 마찬가지로 모달창이 처음 등장했을 때 애니메이션은 적용되지 않은상태입니다.
 
이 부분 관련해서 확인해주실수 있으실까요?

답변 2

·

답변을 작성해보세요.

0

안녕하세요 beegizee1220님, 궁금하신 부분 잘 해결되어서 다행이네요. 참고로 하위 컴포넌트의 루트 엘리먼트 레벨에 v-if 넣으시는 것보다 외부의 컴포넌트 태그 레벨에서 v-if로 넣어서 제어하는 것이 테스트 코드와 명시적인 코딩 차원에서 더 좋습니다 :)

0

아.. Modal.vue 컴포넌트에 v-if 속성을 주고 

TodoInput.vue 컴포넌트에서 v-bind로 props를 내려주는 형태로하면 등장할때도 트랜지션이 잘 적용되네요.

흐음... 강사님 강의에선 왜 된건지 궁금하네요.

버전업되면서 바뀐건지..

여튼 다음과 같이 수정하니까 잘 작동되었습니다!

<template>
<transition name="modal">
<div class="modal-mask" v-if="propsdata">
<div class="modal-wrapper">
<div class="modal-container">

<div class="modal-header">
<slot name="header">
default header
</slot>
</div>

<div class="modal-body">
<slot name="body">
default body
</slot>
</div>
</div>
</div>
</div>
</transition>
</template>

<script>
export default {
name: "Modal",
props: ['propsdata']
}
</script>

<style scoped>
.modal-mask {
position: fixed;
z-index: 9998;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: table;
transition: opacity 0.3s ease;
}

.modal-wrapper {
display: table-cell;
vertical-align: middle;
}

.modal-container {
width: 300px;
margin: 0px auto;
padding: 20px 30px;
background-color: #fff;
border-radius: 2px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.33);
transition: all 0.3s ease;
font-family: Helvetica, Arial, sans-serif;
}

.modal-header h3 {
margin-top: 0;
color: #42b983;
}

.modal-body {
margin: 20px 0;
}

.modal-default-button {
float: right;
}

/*
* The following styles are auto-applied to elements with
* transition="modal" when their visibility is toggled
* by Vue.js.
*
* You can easily play with the modal transition by editing
* these styles.
*/

.modal-enter {
opacity: 0;
}

.modal-leave-active {
opacity: 0;
}

.modal-enter .modal-container,
.modal-leave-active .modal-container {
-webkit-transform: scale(1.1);
transform: scale(1.1);
}
</style>

 

<template>
<div class="inputBox shadow">
<input type="text" v-model="newTodoItem" v-on:keyup.enter="addTodo">
<span class="addContainer" v-on:click="addTodo">
<i class="fas fa-plus addBtn"></i>
</span>
<Modal v-bind:propsdata="showModal">
<h3 slot="header">
경고!
<!-- @는 v-on의 간소화된 문법입니다. short hand -->
<i class="fas fa-times closeModalBtn" @click="showModal=false"></i>
</h3>
<div slot="body">
무언가를 입력하세요.
</div>
</Modal>
</div>
</template>

<script>
import Modal from "@/components/common/Modal";

export default {
name: "TodoInput",
data: function () {
return {
newTodoItem: "",
showModal: false,
}
},
methods: {
addTodo: function () {
if (this.newTodoItem !== '') {
this.$emit('addTodoItem', this.newTodoItem);
this.clearInput();
} else {
this.showModal = !this.showModal;
}
},
clearInput: function () {
this.newTodoItem = '';
},
},
components: {
Modal,
}
}
</script>

<style scoped>
.input:focus {
outline: none;
}
.inputBox {
background-color: #fff;
height: 50px;
line-height: 50px;
border-radius: 5px;
}
.inputBox input {
border-style: none;
font-size: 0.9rem;
}
.addContainer {
float: right;
display: block;
background: linear-gradient(to right, #6478fb, #8763fb);
width: 3rem;
border-radius: 0 5px 5px 0;
}
.addBtn {
color: #ffffff;
vertical-align: middle;
}
.closeModalBtn {
color: #42b983;
}
</style>

 

 

 

뚜다배님의 프로필

뚜다배

2023.10.18

덕분에 해결됐습니다 ㅜㅜ

VUE2 랑 VUE3의 차이점 때문이려나요....