Vue学习(十七)nextTick和过度与动画

nextTick

  1. 语法:this.$nextTick(回调函数)
  2. 作用:在下一次DOM更新接收后执行其指定的回调。
  3. 使用时机:当数据改变后,基于更新后的新DOM进行某些操作时,在nextTick诊所指定的回调函数中执行
handleEdit(todo) {
   
	// todo.isEdit = true;
	if (todo.hasOwnProperty("isEdit")) {
   
		todo.isEdit = true;
	} else {
   
		this.$set(todo, "isEdit", "true");
	}
	/* setTimeout(()=>{
		this.$refs.inputTitle.focus();
	}, 200); */
	// 
	this.$nextTick(function() {
   
		this.$refs.inputTitle.focus();
	});
},

过度与动画

写法

样式准备:

  • 进入样式:
  1. v-enter: 进入的起点
  2. v-enter-active: 进入过程中
  3. v-enter-to: 进入的终点
  • 离开的样式:
  1. v-leave: 离开的起点
  2. v-leave-active: 离开过程中
  3. v-leave-to: 离开的终点

使用

使用<transition></transition>包裹要过度的元素,并配置name属性

<transition name="hello">
    <h1 v-show="isShow">内容</h1>
</transition>

注意:若多个元素需要过度,则需要使用<transition-group></transition-group>进行包裹,且每个子元素都要指定key值

App组件

<template>
    <div>
		<Test/>
		<Test2/>
		<Test3/>
	</div>
</template>

<script>

    import Test from './components/Test'
    import Test2 from './components/Test2'
    import Test3 from './components/Test3'

    export default {
   
        name: "App",
        // 注册组件
        components: {
   Test, Test2,Test3},
    }
</script>

Test组件

<template>
  <div>
    <button @click="isShow = !isShow">显示/隐藏</button>
    <!-- <transition>
        <h1 v-show="isShow" >你好啊!</h1>
    </transition> -->
    <!-- <transition name="myTransition" :appear="true"> -->
    <transition name="myTransition" appear>
        <h1 v-show="isShow" >你好啊!</h1>
    </tra
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值