Skip to content

Commit

Permalink
fix:兼容火狐浏览器无法正确判断元素(#1883) (#1884)
Browse files Browse the repository at this point in the history
  • Loading branch information
wwt444 authored Jun 16, 2024
1 parent 69917a5 commit 3a9f834
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/devui-vue/devui/shared/utils/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ export function isComponent(target: any): target is ComponentPublicInstance {
return !!(target?.$el);
}

/**
* 兼容火狐浏览器判断是否为元素节点
* @param {any} element
* @returns {boolean}
*/
function judgeFireIsElement (element: Element | ComponentPublicInstance | null) {
const str = Object.prototype.toString.call(element);
return str.includes('object')&&str.includes('HTML')&&str.includes('Element');
}

/**
* 提取 Vue Intance 中的元素,如果本身就是元素,直接返回。
* @param {any} element
Expand All @@ -17,13 +27,13 @@ export function isComponent(target: any): target is ComponentPublicInstance {
export function getElement(
element: Element | ComponentPublicInstance | null
): Element | null {
if (element instanceof Element) {
if (element instanceof Element || judgeFireIsElement(element)) {
return element;
}
if (
element &&
typeof element === 'object' &&
element.$el instanceof Element
(element.$el instanceof Element || judgeFireIsElement(element.$el))
) {
return element.$el;
}
Expand Down

0 comments on commit 3a9f834

Please sign in to comment.