zoukankan      html  css  js  c++  java
  • Vue中多个元素或组件的过渡

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Vue中多个元素或组件的过渡</title>
        <script src="./vue.js"></script>
        <style>
            .v-enter,.v-leave-to{
                opacity: 0;
            }
            .v-enter-active,.v-leave-active{
                transition:opacity 1s;
            }
        </style>
    </head>
    <body>
    <div id="root">
        <transition mode="out-in">
            <component :is="type"></component> <!--动态组件的使用-->
            <!--<child v-if="show"></child>-->
            <!--<child-one v-else></child-one>-->
            <!--<div v-if="show" key="hello">hello world</div> &lt;!&ndash;key的创建,避免DOM标签的复用&ndash;&gt;-->
            <!--<div v-else key="bye">Bye World</div>-->
        </transition>
        <button @click="handleClick">toggle</button>
    </div>
    <script>
        Vue.component('child',{
            template:'<div>child</div>'
        });
    
        Vue.component('child-one',{
            template:'<div>child-one</div>'
        });
    
    
        var vm = new Vue({
            el: '#root',
            data: {
                // show: true
                type:'child'
            },
            methods: {
                handleClick: function () {
                    // this.show = !this.show
                    this.type = this.type === 'child' ? 'child-one':'child'
                },
            }
        })
    </script>
    </body>
    </html>
    <!--
    transition上提供了mode配置参数
             mode='in-out'  先显示再隐藏
             mode='out-in'  先隐藏再显示
    -->
  • 相关阅读:
    Beta 冲刺(5/7)
    Beta 冲刺(4/7)
    Beta 冲刺(3/7)
    Beta 冲刺(2/7)
    Beta 冲刺(1/7)
    福大软工 · 第十次作业
    PTA-B 1039 到底买不买 解题思路记录
    SDN负载均衡
    团队作业——项目验收与总结博客
    个人作业——软件工程实践总结作业
  • 原文地址:https://www.cnblogs.com/xuyxbiubiu/p/10020722.html
Copyright © 2011-2022 走看看