diff --git a/packages/taro-weapp/src/lifecycle.js b/packages/taro-weapp/src/lifecycle.js index 5231db082cec..60a1dcb8779b 100644 --- a/packages/taro-weapp/src/lifecycle.js +++ b/packages/taro-weapp/src/lifecycle.js @@ -75,10 +75,11 @@ function doUpdate (component, prevProps, prevState) { return } if (typeof val === 'object') { + if (isEmptyObject(val)) return safeSet(_data, key, val) + val = shakeFnFromObject(val) - if (!isEmptyObject(val)) { - safeSet(_data, key, val) - } + // 避免筛选完 Fn 后产生了空对象还去渲染 + if (!isEmptyObject(val)) safeSet(_data, key, val) } else { safeSet(_data, key, val) } diff --git a/packages/taro-weapp/src/util.js b/packages/taro-weapp/src/util.js index 31015793534b..070c80d53755 100644 --- a/packages/taro-weapp/src/util.js +++ b/packages/taro-weapp/src/util.js @@ -121,7 +121,18 @@ function diffArrToPath (to, from, res = {}, keyPrev = '') { res[targetKey] = toItem } else { // 对象 - diffObjToPath(toItem, fromItem, res, `${targetKey}.`) + let shouldDiffObject = true + Object.keys(fromItem).some(key => { + if (typeof toItem[key] === 'undefined') { + shouldDiffObject = false + return true + } + }) + if (shouldDiffObject) { + diffObjToPath(toItem, fromItem, res, `${targetKey}.`) + } else { + res[targetKey] = toItem + } } } } @@ -142,11 +153,9 @@ export function diffObjToPath (to, from, res = {}, keyPrev = '') { const targetKey = `${keyPrev}${key}` if (toItem === fromItem) { continue - } else - if (!hasProp.call(from, key)) { + } else if (!hasProp.call(from, key)) { res[targetKey] = toItem - } else - if (typeof toItem !== typeof fromItem) { + } else if (typeof toItem !== typeof fromItem) { res[targetKey] = toItem } else { if (typeof toItem !== 'object') { @@ -167,8 +176,19 @@ export function diffObjToPath (to, from, res = {}, keyPrev = '') { if (!toItem || !fromItem) { res[targetKey] = toItem } else { - // 对象 - diffObjToPath(toItem, fromItem, res, `${targetKey}.`) + // 对象 + let shouldDiffObject = true + Object.keys(fromItem).some(key => { + if (typeof toItem[key] === 'undefined') { + shouldDiffObject = false + return true + } + }) + if (shouldDiffObject) { + diffObjToPath(toItem, fromItem, res, `${targetKey}.`) + } else { + res[targetKey] = toItem + } } } }