Vue中this.$nextTick( ) 的用法及详细介绍

理解:将回调延迟到下次 DOM 更新循环之后执行。在修改数据之后立即使用它,然后等待 DOM 更新。

举个例子:假如a组件里面的表格的的  爱好:唱歌  数据点击后-----跳转到b组件-----然后b组件表单的要显示a组件当前行的数据;

分析:a组件和b组件时兄弟关系;

            给a组件的爱好列绑定点击事件,事件内容为$emit带上当前行相应的参数给父组件。

             父组件里面的接收参数,事件为赋值;在a组件里:

 在a组件里面:

<template>
  <el-table
    :data="tableData"
    border
    style="width: 100%">
    <el-table-column
      prop="name"
      label="姓名"
      width="150">
    </el-table-column>
   <el-table-column
      label="爱好"
      width="100">
      <template slot-scope="scope">
        <el-button @click="handleClick(scope.row)" type="text" size="small">唱歌</el-button>
      </template>
    </el-table-column>
    <el-table-column
      prop="age"
      label="年龄"
      width="120">
    </el-table-column>
    <el-table-column
      prop="job"
      label="职业"
      width="300">
    </el-table-column>
  </el-table>
</template>
export default{
    data(){
        return{
            formData:{
                name:"",
                age:"",
                job:"",
                hobby:"",
            }        
        }
    }
}

 在父组件里:

<template>
    <div>
        <keep-alive>
            <component
              :is="activeName"
              @handleClick="handleClick"
              :activeName="activeName"
               :ref="activeName" 
            >
                
            </component>
        <keep-alive>
    </div>
</template>

export default{
    data(){
        activeName:"a"
         formData:{
                name:"",
                age:"",
                job:"",
                hobby:"",
          }      
    },
    methods:{
        handleClick(){
            this.activeName = "b"
            this.$nextTick(()=>{
            this.$refs[this.activeName].formData.name = row.name
            this.$refs[this.activeName].formData.age = row.age
            this.$refs[this.activeName].formData.job= row.job
            this.$refs[this.activeName].formData.hobby= row.hobby
            })
        }
    }
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值