在子组件中Cannot read property ‘setCheckedKeys‘ of undefined

在父组件中有一个dialog子组件,在子组件中有权限列表如图所示
在这里插入图片描述
现在要求可以修改,点击修改的时候,角色所拥有的权限要求回显

   this.$nextTick(()=>{
      this.$refs.tree.setCheckedKeys(this.resourceCheckedKey)
   })

使用element ui给出的方法,还是报错了
在这里插入图片描述
去网上查了,结果说是dom数没来得及渲染,就要预勾选,所以报错了,然后说加this. n e x t T i c k , 道 理 我 都 懂 , 但 是 我 是 单 独 做 了 一 个 子 组 件 的 , 父 子 组 件 生 命 周 期 钩 子 为 ∗ ∗ 父 b e f o r e C r e a t e − > 父 c r e a t e d − > 父 b e f o r e M o u n t − > 子 b e f o r e C r e a t e − > 子 c r e a t e d − > 子 b e f o r e M o u n t − > 子 m o u n t e d − > 父 m o u n t e d ∗ ∗ 这 样 的 话 不 管 怎 么 使 用 t h i s . nextTick,道理我都懂,但是我是单独做了一个子组件的, 父子组件生命周期钩子为 **父beforeCreate->父created->父beforeMount->子beforeCreate->子created->子beforeMount->子mounted->父mounted** 这样的话不管怎么使用this. nextTick,,,beforeCreate>created>beforeMount>beforeCreate>created>beforeMount>mounted>mounted使this.nextTick都是没用的,我们只能在父组件中做延迟加载,
我们在子组件中使用this.$nextTick方法渲染一个方法

     this.$nextTick(()=>{
        this.$refs.editDialog.init()
      })

editDialog为子组件的ref,init为子组件中的方法
在子组件的申明一个方法

    init() {
    this.$nextTick(()=>{
      this.$refs.tree.setCheckedKeys(this.resourceCheckedKey)
   })
    },

这样就不会报错了

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值