【多个元素过渡】
<html>
<head>
<meta charset="utf-8" />
<title>Vue中多个 元素和组件的过渡</title>
<script src="./vue.js"></script>
<script src="./velocity.js"></script>
<style>
.v-enter, .v-leave {
opacity: 0
}
.v-enter-active, .leave-active {
transition: opacity 1s
}
</style>
</head>
<body>
<!--in-out 先显示再隐藏,out-in先隐藏 再显示-->
<div id="root" mode="in-out">
<transition>
<div v-if="show" key="'hellow">hellow world</div>
<div v-else track-by="bye">bye world</div>
</transition>
<button @click="handleClick">toggle</button>
</div>
<script>
var vm = new Vue({
el: "#root",
data: {
show: true
},
methods: {
handleClick: function () {
this.show = !this.show
},
}
})
</script>
</body>
</html>

【多个组件过渡1】
<html>
<head>
<meta charset="utf-8" />
<title>Vue中多个 元素和组件的过渡</title>
<script src="./vue.js"></script>
<script src="./velocity.js"></script>
<style>
.v-enter, .v-leave {
opacity: 0
}
.v-enter-active, .leave-active {
transition: opacity 1s
}
</style>
</head>
<body>
<!--in-out 先显示再隐藏,out-in先隐藏 再显示-->
<div id="root" mode="in-out">
<transition>
<child v-if="show"></child>
<child-one v-else></child-one>
</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
},
methods: {
handleClick: function () {
this.show = !this.show
},
}
})
</script>
</body>
</html>
【多个组件过渡2】
<html>
<head>
<meta charset="utf-8" />
<title>Vue中多个 元素和组件的过渡</title>
<script src="./vue.js"></script>
<script src="./velocity.js"></script>
<style>
.v-enter, .v-leave {
opacity: 0
}
.v-enter-active, .leave-active {
transition: opacity 1s
}
</style>
</head>
<body>
<!--in-out 先显示再隐藏,out-in先隐藏 再显示-->
<div id="root" mode="in-out">
<transition>
<component :is="type"></component>
</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.type = this.type === 'child' ? 'child-one' : 'child'
},
}
})
</script>
</body>
</html>

网友评论