vue中组件的过渡动画

news/2024/7/24 8:31:36 标签: vue, 组件过渡

1.  和多个元素的过渡一样,用组件来替换transition中包裹的标签

  <style>
    .fade-enter,
    .fade-leave-to {
      opacity: 0
    }
    .fade-enter-active,
    .fade-leave-active {
      transition: opacity 2s
    }
  </style>
</head>

<body>
  <div id="demo">
    <button @click="show = !show">click me</button>
    <transition name="fade" mode="in-out">
      <child-one v-if="show"></child-one>
      <child-two v-else></child-two>
    </transition>
  </div>
  <script>
    Vue.component('child-one', {
      template: `<div>child-one</div>`
    })
    Vue.component('child-two', {
      template: `<div>child-two</div>`
    })
    new Vue({
      el: '#demo',
      data: {
        show: true
      },
    })
  </script>

2.  动态组件:component组件 :is 属性,来实现组件的过渡效果

  <style>
    .fade-enter,
    .fade-leave-to {
      opacity: 0
    }
    .fade-enter-active,
    .fade-leave-active {
      transition: opacity 2s
    }
  </style>
</head>

<body>
  <div id="demo">
    <button @click="handleClick">click me</button>
    <transition name="fade" mode="in-out">
      <component :is="type"></component>
    </transition>
  </div>
  <script>
    Vue.component('child-one', {
      template: `<div>child-one</div>`
    })
    Vue.component('child-two', {
      template: `<div>child-two</div>`
    })
    new Vue({
      el: '#demo',
      data: {
        type: 'child-one'
      },
      methods:{
        handleClick () {
          this.type = this.type === 'child-one' ? 'child-two' : 'child-one'
        }
      }
    })
  </script>

 


http://www.niftyadmin.cn/n/584632.html

相关文章

vue中列表增删时的动画过渡效果

用transition-group 包裹标签&#xff0c;注意没有name属性&#xff0c;要使用v-enter等类 <style>.v-enter,.v-leave-to {opacity: 0}.v-enter-active,.v-leave-active {transition: opacity 2s}</style> </head><body><div id"demo">…

wpf 路由事件

路由事件 可以从功能或实现的角度来理解路由事件。 此处对这两种定义均进行了说明&#xff0c;因为有的用户认为前者更有用&#xff0c;有的用户认为后者更有用。 请思考下面的简单代码&#xff1a; <Window x:Class"路由事件.MainWindow"xmlns"http://sc…

vue中用组件封装过渡动画

组件中要有props接收一个值&#xff0c;比如&#xff1a;show&#xff1b;组件的template中transition和slot的结合&#xff0c;可以接收父组件中的标签&#xff1b;过渡效果通过js钩子函数实现。这样就可以实现自己封装过渡动画&#xff0c;在项目中复用。 <body><d…

鼠标指针位置

鼠标指针位置有3个&#xff0c;一个是相对窗口来说的相对位置&#xff0c;一个是相对屏幕来说的绝对位置&#xff0c;还有个一个是相对窗口客户区来说的相对位置&#xff0c;所以单独说鼠标位置不明确的&#xff0c;需要具体说明相对那个来说的鼠标位置 思考下面相对窗口客户区…

(1)用vue写项目——项目准备

方法一&#xff1a; 1. 下载安装nodejs和git 2. 全局安装vue脚手架vue-cli 3. 执行命令创建一个基于webpack打包工具的vue项目的文件夹 命令会进入该项目的配置选项&#xff1a; Project name 项目名字quna.com quna.comProject description 项目描述A Vue.js project about m…

Oeacle 表的管理

1建表 语法&#xff1a; Create table 表名&#xff08; 字段1 数据类型 [default 默认值], 字段2 数据类型 [default 默认值], ... 字段n 数据类型 [default 默认值] &#xff09;; 范例&#xff1a;创建person表 create table person(…

(2)用vue写项目——项目文件结构

README.md项目描述说明文件 package.json 安装依赖的包 index.html 首页模板&#xff0c;项目的首页 postcssrc.js&#xff1a;是post的配置项 gitignore&#xff1a;有些文件不需要用git上传&#xff0c;不需要上传 eslintrc.js&#xff1a;代码规范&#xff0c;按eslint…

(3)用vue写去哪网——单文件组件代码结构

1. 首页文件&#xff1a;index.html <!DOCTYPE html> <html><head><meta charset"utf-8"><meta name"viewport" content"widthdevice-width,initial-scale1.0"><title>quna.com</title></head>…