๋ชจ๋ฌ์ ํธ๋์ง์ ์์ฑ์ ๋ฃ๋ ๊ณผ์ ์์ 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
'๐ Front > ๐ฅ Vue.js' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Vue.js ํ๊ฒฝ ๊ตฌ์ถ ์ ๋ฐ์ํ๋ ์ค๋ฅ(executionpolicy) (0) | 2021.12.22 |
---|