Skip to content

Commit c1afa1d

Browse files
committed
Update index.jsx
1 parent 8911fe1 commit c1afa1d

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

packages/ve-dropdown/src/index.jsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -388,18 +388,22 @@ export default {
388388

389389
// add root contextmenu panel to body
390390
addRootElementToBody() {
391-
const { rootId } = this;
391+
this.rootId = this.getRandomIdWithPrefix();
392+
this.dropdownItemsPanelId = this.getRandomIdWithPrefix();
392393

393-
let rootEl = document.querySelector(`#${rootId}`);
394+
let rootEl = document.querySelector(`#${this.rootId}`);
394395

395396
if (rootEl) {
396397
return false;
397398
} else {
398-
let containerEl = document.createElement("div");
399+
// fixed unit test error: [Vue warn]: Error in v-on handler: "TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'."
400+
this.$nextTick(() => {
401+
let containerEl = document.createElement("div");
399402

400-
containerEl.setAttribute("id", rootId);
403+
containerEl.setAttribute("id", this.rootId);
401404

402-
document.body.appendChild(containerEl);
405+
document.body.appendChild(containerEl);
406+
});
403407
}
404408
},
405409
},
@@ -408,8 +412,6 @@ export default {
408412
this.init();
409413
},
410414
mounted() {
411-
this.rootId = this.getRandomIdWithPrefix();
412-
this.dropdownItemsPanelId = this.getRandomIdWithPrefix();
413415
this.addRootElementToBody();
414416

415417
document.addEventListener("scroll", this.changDropdownPanelPosition);

0 commit comments

Comments
 (0)