From 3703f77c0bb5bd31b261711e474d4abceb95af86 Mon Sep 17 00:00:00 2001 From: WumaCoder <1829913225@qq.com> Date: Thu, 24 Sep 2020 16:31:31 +0800 Subject: [PATCH] fix: tree extract the public method --- packages/tree/Tree.vue | 3 ++- packages/tree/libs/util.js | 14 ++++---------- src/utils/types.js | 3 +++ 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/tree/Tree.vue b/packages/tree/Tree.vue index 74db496bb..9215d7075 100644 --- a/packages/tree/Tree.vue +++ b/packages/tree/Tree.vue @@ -36,7 +36,8 @@ import { Tree } from './entity/Tree' import ElTreeNode from './TreeNode.vue' import { t } from 'element-ui/src/locale' -import { extractMethods, isFunction } from './libs/util' +import { isFunction } from 'element-ui/src/utils/types' +import { extractMethods } from './libs/util' import { reactive, diff --git a/packages/tree/libs/util.js b/packages/tree/libs/util.js index d83a6ab94..92a097cdf 100644 --- a/packages/tree/libs/util.js +++ b/packages/tree/libs/util.js @@ -1,12 +1,5 @@ -export function isArray(value) { - return value instanceof Array -} -export function isObject(value) { - return value instanceof Object && !(value instanceof Array) -} -export function isFunction(value) { - return value instanceof Function -} +import { isArray, isObject } from 'element-ui/src/utils/types' + /** * Deep traversal of the object * @param {object} target @@ -47,9 +40,10 @@ export function nodeEach( { childKey = 'children', root = null } = {} ) { const dfs = (node) => { - if (!isObject(node)) { + if (!isObject(node) || isArray(node)) { return } + const child = node[childKey] || [] for (let i = 0; i < child.length; i++) { diff --git a/src/utils/types.js b/src/utils/types.js index f707c94ac..917862562 100644 --- a/src/utils/types.js +++ b/src/utils/types.js @@ -6,6 +6,9 @@ export function isObject(obj) { return Object.prototype.toString.call(obj) === '[object Object]' } +export function isArray(value) { + return value instanceof Array +} export function isHtmlElement(node) { return node && node.nodeType === Node.ELEMENT_NODE }