console
var vm1 = new Vue({
el:'#app1',
data () {
return{
isEditing:true,
}
}
})
var vm2 = new Vue({
el:'#app2',
data () {
return {
on:true
}
}
})
var vm3 = new Vue({
el:'#app3',
data () {
return {
on:true
}
}
})
var vm4 = new Vue({
el:'#app4',
data () {
return {
on:true
}
}
})
<div id="app1">
<transition name="fade" mode="out-in">
<button v-if="isEditing" key="save" @click="isEditing = !isEditing">
save
</button>
<button v-else key="edit" @click="isEditing = !isEditing">
Edit
</button>
</transition>
</div>
<div id="app2">
<transition name="fade-abosolute">
<button v-if="on" key="on" @click="on = !on">
on
</button>
<button v-else key="off" @click="on = !on">
off
</button>
</transition>
</div>
<div id="app3">
<transition name="fade-slide">
<button v-if="on" key="on" @click="on = !on">
on
</button>
<button v-else key="off" @click="on = !on">
off
</button>
</transition>
</div>
<div id="app4">
<transition name="fade-slide-mode" mode="in-out">
<button v-if="on" key="on" @click="on = !on">
on
</button>
<button v-else key="off" @click="on = !on">
off
</button>
</transition>
</div>
.fade-enter-active,.fade-leave-active{
transition: all .5s
}
.fade-enter,.fade-leave-active{
opacity: 0
}
#app2{
position: relative;
height: 100px;
width: 100px;
background:green;
}
#app2 button{
position: absolute;
left:50%;
top: 50%;
}
.fade-abosolute-enter,.fade-abosolute-leave-active{
opacity: 0
}
.fade-abosolute-enter-active,.fade-abosolute-leave-active{
transition: all 1s
}
#app3{
width: 200px;
height: 100px;
background: rgb(26, 46, 224);
position: relative;
}
#app3 button{
position: absolute;
left: 50%;
top: 50%;
}
.fade-slide-enter-active,.fade-slide-leave-active{
transition: all 1s
}
.fade-slide-enter{
opacity: 0;
transform: translateX(30px);
}
.fade-slide-leave-active{
opacity: 0;
transform: translateX(-30px);
}
#app4{
position: relative;
width: 200px;
height: 100px;
background: rgb(8, 201, 80);
}
#app4 button{
position: absolute;
left: 50%;
top: 50%;
}
.fade-slide-mode-enter-active,.fade-slide-mode-leave-active{
transition: all .5s
}
.fade-slide-mode-enter{
opacity: 0;
transform: translateX(30px);
}
.fade-slide-mode-leave-active{
opacity: 0;
transform: translateX(-30px);
}