ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
~~~ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Vue中多个元素或组件的过渡</title> <script src="vue.js"></script> <!-- <script src="velocity.min.js"></script>--> <style> .v-enter, v-leave-to { opacity: 0; } .v-enter-active, .v-leave-active { transition: opacity 500ms; } </style> </head> <body> <div id="root"> <transition mode="out-in"> <!-- <div v-if="show" key="hello">Hello World</div>--> <!-- <div v-else key="bye">Bye World</div>--> <!-- <child-one v-if="show"></child-one>--> <!-- <child-two else></child-two>--> <!-- 动态组件--> <component :is="type"></component> <!-- 动态组件--> </transition> <button @click="handleClick">toggle</button> </div> <script> Vue.component('child-one', { template: '<div>child-one</div>' }) Vue.component('child-two', { template: '<div>child-two</div>' }) var vm = new Vue({ el: '#root', data: { show: true, type: 'child-one' }, methods: { handleClick() { this.show = !this.show this.type = this.type == 'child-one' ? 'child-two' : 'child-one'; } } }) </script> </body> </html> ~~~