在组件当中应用动画很简单,直接拿一个transition标签将组件包裹起来,再给订一些样式即可,定义组件动画时,transition身上有个mode属性,来决定动画执行的顺序问题,有out-in和in-out两个属性值
例:
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="js/vue.js"></script>
<style>
.v-enter,
.v-leave-to {
opacity: 0;
transform: translateX(150px)
}
.v-enter-active,
.v-leave-active {
transition: all .6s ease;
}
</style>
</head>
<body>
<div id="app">
<button @click="componentId='mycom1'">按钮</button>
<button @click="componentId='mycom2'">按钮</button>
<button @click="componentId='mycom3'">按钮</button>
<!-- component标签相当于是一个占位符 -->
<transition mode='out-in'>
<component :is="componentId"></component>
</transition>
</div>
<template id="tem1">
<h1>hello world1</h1>
</template>
<template id="tem2">
<h1>hello world2</h1>
</template>
<template id="tem3">
<h1>hello world3</h1>
</template>
<script>
Vue.component('mycom1', {
template:'#tem1'
})
Vue.component('mycom2', {
template:'#tem2'
})
Vue.component('mycom3', {
template:'#tem3'
})
var vm = new Vue({
el: '#app',
data: {
componentId: 'mycom1'
},
methods: {}
});
</script>
</body>
</html>
网友评论