2020年3月29日日曜日

Vue.js記法:Transitionのin-out表現

単一コンポネントの場合、transitionに含まれるだけ

<transition name="component-fade" mode="out-in"> <component v-bind:is="view"></component> </transition>

<script>
new Vue({ el: '#transition-components-demo', data: { view: 'v-a' }, components: { 'v-a': { template: '<div>Component A</div>' }, 'v-b': { template: '<div>Component B</div>' } } })
</script>

<style>
.component-fade-enter-active, .component-fade-leave-active { transition: opacity .3s ease; } .component-fade-enter, .component-fade-leave-to /* .component-fade-leave-active for below version 2.1.8 */ { opacity: 0; }
</style>

複数コンポネントの場合、transition-groupを使って

<div id="list-demo" class="demo"> <button v-on:click="add">Add</button> <button v-on:click="remove">Remove</button> <transition-group name="list" tag="p"> <span v-for="item in items" v-bind:key="item" class="list-item"> {{ item }} </span> </transition-group> </div>

new Vue({ el: '#list-demo', data: { items: [1,2,3,4,5,6,7,8,9], nextNum: 10 }, methods: { randomIndex: function () { return Math.floor(Math.random() * this.items.length) }, add: function () { this.items.splice(this.randomIndex(), 0, this.nextNum++) }, remove: function () { this.items.splice(this.randomIndex(), 1) }, } })

.list-item { display: inline-block; margin-right: 10px; } .list-enter-active, .list-leave-active { transition: all 1s; } .list-enter, .list-leave-to /* .list-leave-active for below version 2.1.8 */ { opacity: 0; transform: translateY(30px); }


0 件のコメント:

コメントを投稿

ITIL4 Foundation Study Guide 2 : 4 Dimensions and 6 Factors

4  Dimensions:  Dimension1: Organizations & People Dimension2: Information & Technology Dimension3: Partners & Suppliers D...