Vue动画--两个元素过渡

code:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>Vue中两个元素过渡</title>
		<script type="text/javascript" src="js/vue.js" ></script>
		<style>
			.fade-enter,.fade-leave-to{
				opacity: 0;
			}
			.fade-enter-active,.fade-leave-active{
				transition: opacity 3s;
			}
		</style>
	</head>
	<body>
		<div id="root">
		<!--	mode设置元素切换时的效果-->
			<transition name="fade" mode="out-in">
			<!--	添加key值,阻止vue对元素进行复用-->
				<div v-if="show" key="hello">hello world</div>
				<div v-else key="bye">Bye world</div>
			</transition>
			<button @click="handleClick">切换</button>
		</div>
		<script>
			new Vue({
				el:"#root",
				data:{
					show:true
				},
				methods:{
					handleClick(){
						this.show=!this.show
					}
				}
			})
		</script>
	</body>
</html>

猜你喜欢

转载自blog.csdn.net/AsaZyf/article/details/83783724