diff --git a/packages/uni-mp-baidu/dist/index.js b/packages/uni-mp-baidu/dist/index.js index c9ea13f83b486bc1e78f1b228dae384d259c461a..5b51e7d344c91f39841f24924a4a2ed94f4f1e8a 100644 --- a/packages/uni-mp-baidu/dist/index.js +++ b/packages/uni-mp-baidu/dist/index.js @@ -1962,6 +1962,44 @@ function stringifyQuery (obj, encodeStr = encode) { return res ? `?${res}` : '' } +/** + * 用于延迟调用 setData + * 在 setData 真实调用的时机需执行 fixSetDataEnd + * @param {*} mpInstance + */ +function fixSetDataStart (mpInstance) { + const setData = mpInstance.setData; + const setDataArgs = []; + mpInstance.setData = function () { + setDataArgs.push(arguments); + }; + mpInstance.__fixInitData = function () { + this.setData = setData; + const fn = () => { + setDataArgs.forEach(args => { + setData.apply(this, args); + }); + }; + if (setDataArgs.length) { + if (this.groupSetData) { + this.groupSetData(fn); + } else { + fn(); + } + } + }; +} +/** + * 恢复真实的 setData 方法 + * @param {*} mpInstance + */ +function fixSetDataEnd (mpInstance) { + if (mpInstance.__fixInitData) { + mpInstance.__fixInitData(); + delete mpInstance.__fixInitData; + } +} + function parseBaseComponent (vueComponentOptions, { isPage, initRelation @@ -2075,22 +2113,7 @@ function parseComponent (vueOptions) { } // 处理百度小程序 onInit 生命周期调用 setData 无效的问题 - const setData = this.setData; - const setDataArgs = []; - this.setData = function () { - setDataArgs.push(arguments); - }; - this.__fixInitData = function () { - delete this.__fixInitData; - this.setData = setData; - if (setDataArgs.length) { - this.groupSetData(() => { - setDataArgs.forEach(args => { - setData.apply(this, args); - }); - }); - } - }; + fixSetDataStart(this); oldAttached.call(this); this.pageinstance.$vm = this.$vm; this.$vm.__call_hook('onInit', query); @@ -2100,7 +2123,7 @@ function parseComponent (vueOptions) { oldAttached.call(this); } else { initMocks(this.$vm, mocks); - this.__fixInitData && this.__fixInitData(); + fixSetDataEnd(this); } if (isPage.call(this)) { // 百度 onLoad 在 attached 之前触发(基础库小于 3.70) // 百度 当组件作为页面时 pageinstancce 不是原来组件的 instance diff --git a/packages/uni-mp-kuaishou/dist/index.js b/packages/uni-mp-kuaishou/dist/index.js index 22578bf2b36bb50d8a79c124db5d9b593640843d..d84013df63fbcc3e9120269bf512360a0dcaa0a5 100644 --- a/packages/uni-mp-kuaishou/dist/index.js +++ b/packages/uni-mp-kuaishou/dist/index.js @@ -1803,8 +1803,60 @@ function parseComponent (vueComponentOptions) { }) } +/** + * 用于延迟调用 setData + * 在 setData 真实调用的时机需执行 fixSetDataEnd + * @param {*} mpInstance + */ +function fixSetDataStart (mpInstance) { + const setData = mpInstance.setData; + const setDataArgs = []; + mpInstance.setData = function () { + setDataArgs.push(arguments); + }; + mpInstance.__fixInitData = function () { + this.setData = setData; + const fn = () => { + setDataArgs.forEach(args => { + setData.apply(this, args); + }); + }; + if (setDataArgs.length) { + if (this.groupSetData) { + this.groupSetData(fn); + } else { + fn(); + } + } + }; +} +/** + * 恢复真实的 setData 方法 + * @param {*} mpInstance + */ +function fixSetDataEnd (mpInstance) { + if (mpInstance.__fixInitData) { + mpInstance.__fixInitData(); + delete mpInstance.__fixInitData; + } +} + +const SDKVersion = ks.getSystemInfoSync().SDKVersion; + function parseComponent$1 (vueComponentOptions) { - return parseComponent(vueComponentOptions) + const componentOptions = parseComponent(vueComponentOptions); + const oldAttached = componentOptions.lifetimes.attached; + componentOptions.lifetimes.attached = function attached () { + if (isPage.call(this) && parseFloat(SDKVersion) <= 1.13) { + // 解决快手小程序页面 attached 生命周期 setData 导致数据同步异常的问题 + fixSetDataStart(this); + setTimeout(() => { + fixSetDataEnd(this); + }, 0); + } + oldAttached.call(this); + }; + return componentOptions } const hooks$1 = [