在父组件中有一个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)
})
},
这样就不会报错了