在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ TypeError: Cannot read property 'setChec

TypeError: Cannot read property 'setCheckedKeys' of undefined

在角色資源管理的時(shí)候 點(diǎn)擊設(shè)置資源 彈出資源列表的樹 ,并且賦上默認(rèn)值,但是在第一次調(diào)用彈出層的方法,會(huì)報(bào)這個(gè)錯(cuò),第二次點(diǎn)擊的時(shí)候不會(huì)報(bào)這個(gè)錯(cuò) 而且 getHalfCheckedKeys也使用不了

圖片描述

 handleSetResource(val) {
    this.Visible = true
    this.Status = 'setResource'
    const currRes = val.resources
    for(const v of currRes){
      console.log(v.id)
      this.$refs.tree.setCheckedKeys([v.id]);
    }
  },
  getHalfCheckedKeys() {
    console.log(this.$refs.tree.getHalfCheckedKeys());
  },
回答
編輯回答
毀與悔

在彈出dialog之前執(zhí)行$nextTick回調(diào)函數(shù),確保el-tree已經(jīng)渲染

this.visible = true;
this.$nextTick(() => {
    // code
});
2018年5月10日 13:31
編輯回答
夏夕

應(yīng)該是第一次彈框的時(shí)候,樹還沒有加載完成,所以獲取不到,第二次的時(shí)候樹已經(jīng)加載完成,所以可以調(diào)用方法。

2018年8月5日 06:10