当前位置: 首页 > 工具软件 > Easy Slide > 使用案例 >

Vue转场动画(So easy!)

羊舌青青
2023-12-01

Vue转场动画

<template>
  <div id="app">
    <transition :name="transitionName">
      <keep-alive>
        <router-view class="child-view "></router-view>
      </keep-alive>
    </transition>
  </div>
</template>

<script>
export default {
  name: "app",
  data() {
    return {
      transitionName: "slide-left"
    };
  },
  watch: {
    $route(to, from) {
        //页面的进出通过路由上的index参数来决定
      const prevStamps = from.query.stamps || 0;
      const nextStamps = to.query.stamps || 0;
      this.transitionName =
        prevStamps > nextStamps ? "slide-right" : "slide-left";
    }
  }
};
</script>

.child-view {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  transition-property: transform,opacity;
  transition-duration: 0.6s;
  transition-timing-function: ease-out;
  background-color: #ffffff;
  display: flex;//有bug去掉
  flex-direction: column;//有bug去掉
}
.slide-left-enter {
  opacity: 0;
  transform: translate(100%, 0);
}
.slide-left-enter-active {
  z-index: 10;
}
.slide-left-leave-active {
  z-index: 0;
}
.slide-right-leave-active {
  opacity: 0;
  transform: translate(100%, 0);
  z-index: 11;
}

路由里面加一个判断是左滑动,右滑动
比如当前路由级是index:1,要去到index:2,watch就会监听到,然后给出相应的css动画

{
	path:"/path",
	name:"name",
	compoent:()=>{
		import("../view/home")
	},
	meta:{
		index:1
	}
}

 类似资料: