显示隐藏
<!DOCTYPE html>
<html lang="en">
<head>
<title>Vue动画</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="./vue.js"></script>
</head>
<body>
<div id="app">
<p v-if='isShow'>{{name}}</p>
<button @click='isShow=!isShow'>点击</button>
</div>
<script>
var vm = new Vue({
el: '#app',
data: {
name: 'vivi',
isShow: true
}
})
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Vue动画</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="./vue.js"></script>
<style>
/* 2.定义类名 */
/* 定义进入过渡的开始状态 */
.slide-enter,
.slide-leave-to {
padding-left: 100px;
}
.slide-enter-active,
.slide-leave-active {
transition: all 2s;
}
.slide-enter-to,
.slide-leave {
padding-left: 0;
}
</style>
</head>
<body>
<div id="app">
<!-- 1.找到需要加过渡的元素,把它用transition标签包裹起来,然后给transition标签指定name属性
这个name 属性会作为类名的前缀
-->
<transition name='slide'>
<p v-if='isShow'>{{name}}</p>
</transition>
<button @click='isShow=!isShow'>点击</button>
</div>
<script>
var vm = new Vue({
el: '#app',
data: {
name: 'vivi',
isShow: true
}
})
</script>
</body>
</html>