我有一個列表,如果您單擊打開它并列出子項,則發出請求 ajax 以加載數據并繪制子列表,執行此工作的組件是相同的,是遞歸的并加載到子項上通過動態組件,問題在于當您加載第二個列表的子項時。并打開三分之一這些重復。import * from '....';export default { name: 'cList', components : { itett, }, props : ['id', 'entity', 'treeData'], data : ()=>{return{ loading: true, tree: {}, child_component: false, tdata: false, }}, methods: { clop: function(state, uid, ev){ let _childs = document.querySelector(`[data-idml="${uid}"]`); if( _childs ) { switch (state) { case 'close': _childs.classList.add('hide'); break; case 'open' : _childs.classList.remove('hide'); this.getChildren(uid); break; } } }, getChildren: function( uid ){ this.child_component = false; let _tdata = {}; let de = uid.split('_'); let _elm = Entity.create({ is: de[0], id: de[1] }); let tot = _elm.childs.length - 1, cnt = 0; _elm.childs.forEach((et, ix) => { if( _elm.type && _elm.id ) { ApiEntity.getList({ entity: et, parents: [+_elm.id], parentType: _elm.type, cascade: false, }).then(res => { if( Array.isArray(res) ) { _tdata[et] = res; } if( cnt >= tot ) { this.tdata = _tdata; this.child_component = 'cList'; } cnt++; }).catch( err => { console.error( err ); }); } }); }, seeMore: function(uid){ } },
vue 動態組件,重復信息
慕碼人8056858
2021-10-21 14:47:17