๋ณธ๋ฌธ์œผ๋กœ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๋ชจ๋‹ฌ์— ํŠธ๋žœ์ง€์…˜ ์†์„ฑ์„ ๋„ฃ๋Š” ๊ณผ์ •์—์„œ Vue ๋ฒ„์ „์ฐจ์ด๋กœ ์ธํ•ด ์ด์Šˆ๊ฐ€ ๋ฐœ์ƒํ–ˆ๋‹ค.

 

1. <transition>์„ ๋ชจ๋‹ฌ ์ปดํฌ๋„ŒํŠธ ์•ˆ์— ์„ ์–ธํ•˜๊ณ  ์‹ถ์€๋ฐ?

 <transition name="modal">
  <modal v-if="showModal" @close="showModal = false">
    <!--
      you can use custom content here to overwrite
      default content
    -->
    <template v-slot:header>
      <h3>custom header</h3>
    </template>
  </modal>
  </transition>

์œ„์˜ ์ฝ”๋“œ์ฒ˜๋Ÿผ ์ž‘์„ฑํ•˜๋ฉด modal์˜ ์• ๋‹ˆ๋ฉ”์ด์…˜์„ ๋‹ด๋‹นํ•˜๋Š” <transition>์ด ๋ชจ๋‹ฌ ์ปดํฌ๋„ŒํŠธ์™€ ๋ถ„๋ฆฌ๋œ๋‹ค. ๊ฐ€๋…์„ฑ์ด ๋งค์šฐ ๋–จ์–ด์ง„๋‹ค.

 

2. Vue 2.x ๊ณต์‹๋ฌธ์„œ ์˜ˆ์‹œ

<!-- modal component -->
<template>
  <transition>
    <div class="modal"><slot/></div>
  </transition>
</template>
<!-- usage -->
<modal v-if="showModal">hello</modal>

Vue2.x ๊ณต์‹๋ฌธ์„œ๋Œ€๋กœ ๋ชจ๋‹ฌ์•ˆ์— ํŠธ๋žœ์ง€์…˜์ด ๋“ค์–ด๊ฐ„ ์ฝ”๋“œ๋ฅผ ์„ค์ •ํ•ด๋„ ์›ํ•˜๋Š” ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜ค์ง€ ์•Š์•˜๋‹ค.

๊ทธ๋ฆฌ๊ณ  Vue2.x ์—์„œ๋Š” ๋ชจ๋‹ฌ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์“ฐ๋Š” ๋ฃจํŠธ ์ปดํฌ๋„ŒํŠธ์—์„œ v-if ์†์„ฑ์„ ์‚ฌ์šฉํ•˜์—ฌ ํŠธ๋žœ์ง€์…˜์„ ์ž‘๋™์‹œ์ผฐ๋‹ค.

ํ•˜์ง€๋งŒ <transition>์€ ์ž์‹ ์š”์†Œ๋“ค์— ์˜ํ•ด์„œ ์ž‘๋™ํ•ด์•ผ์ง€, <transition>์ž์ฒด๊ฐ€ ํ† ๊ธ€๋ง๋˜๋ฉด ์•ˆ๋œ๋‹ค๊ณ  ํ•œ๋‹ค.

 

3. Vue 3.x migration strategy

<!-- modal component -->
<template>
  <transition>
    <div v-if="show" class="modal"><slot/></div>
  </transition>
</template>
<script>
export default {
  props: ['show']
}
</script>
<!-- usage -->
<modal :show="showModal">hello</modal>

์ด๋Š” prop์„ ํ•˜์œ„ ์ปดํฌ๋„ŒํŠธ์— ์ „๋‹ฌํ•˜์—ฌ ํŠธ๋žœ์ง€์…˜ ํ•˜์œ„ ์—˜๋ฆฌ๋จผํŠธ๋ฅผ on/offํ•˜๋Š” ๊ฒƒ์œผ๋กœ ํ†ต์ œํ•œ๋‹ค.

 

 

๋ ˆํผ๋Ÿฐ์Šค

1) https://vuejs.org/v2/examples/modal.html

 

Modal Component — Vue.js

Vue.js - The Progressive JavaScript Framework

vuejs.org

2) https://v3.vuejs.org/examples/modal.html#modal-component

 

Modal Component | Vue.js

Modal Component Features used: component, prop passing, content insertion, transitions. See the Pen Vue 3 Modal Component by Vue (@Vue) on CodePen. ← SVG Graph Elastic Header Example →

v3.vuejs.org

3) https://v3.vuejs.org/guide/migration/transition-as-root.html#overview

 

Transition as Root | Vue.js

Transition as Root breaking Overview Using a as a component's root will no longer trigger transitions when the component is toggled from the outside. 2.x Behavior In Vue 2, it was possible to trigger a transition from outside a component by using a as the

v3.vuejs.org

 

๋ฐ˜์‘ํ˜•