_
2023/12/14 09:00:53654

上节课我们学到了自定义过渡动画的className,这个功能在你想要在 Vue 的动画机制下集成其他的第三方 CSS 动画库时非常有用。

我们以为第三个库Animate.css动画库为例,我们在上节课的代码上进行一下修改,删除掉多余的代码

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>document</title>
</head>
<script src="https://unpkg.com/vue@next"></script>

<body>
  <div id="app"></div>
</body>
<script>
  const app = Vue.createApp({
    data() {
      return {
        message: "hello world!",
        isShow:false
      }
    },
    methods: {
      handelClick() {
        this.isShow = !this.isShow
      }
    },
    template: `
      <Transition>
        <div v-if="isShow">{{message}}</div>
      </Transition>
      <button @click="handelClick">显示/隐藏</button>
    `
  })
  const vm = app.mount("#app")
</script>

</html>

我们这里以cdn的方式引入一下这个css库。

<head>
  <link
    rel="stylesheet"
    href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"
  />
</head>

然后通过自定义class选择器的方式来使用Animate.css动画效果

template: `
      <Transition
        enter-active-class="animate__animated animate__backInUp"
        leave-active-class="animate__animated animate__backOutDown"
      >
        <div v-if="isShow">{{message}}</div>
      </Transition>
      <button @click="handelClick">显示/隐藏</button>
    `

好,那么这节课就先到这里

视频讲解