diff --git a/packages/taro-plugin-react/src/runtime/connect-native.ts b/packages/taro-plugin-react/src/runtime/connect-native.ts index e3f5a127329b..56270e2c91ba 100644 --- a/packages/taro-plugin-react/src/runtime/connect-native.ts +++ b/packages/taro-plugin-react/src/runtime/connect-native.ts @@ -368,11 +368,25 @@ export function createNativeComponentConfig (Component, react: typeof React, rea type: null, value: null, observer (_newVal, oldVal) { + if (process.env.TARO_ENV === 'swan') { + // 百度模版传递 props 时 函数参数会被忽略,这里需要根据 id 获取 TaroElement 中的 props 赋值到 ctx.data 中 + const inst: any = document.getElementById(this.id) + if (this.component?.ctx?.data && inst) { + this.component.ctx.data.props = inst?.props?.props + } + } oldVal && this.component?.forceUpdate() } } }, created () { + if (process.env.TARO_ENV === 'swan') { + const inst: any = document.getElementById(this.id) + // 百度小程序 真机上 props中的函数会被转为Object 调用报错 导致后续组件无法渲染 这里先取TaroElement上的props,在properties中会重新赋值 + if (this.data?.props && inst) { + this.data.props = inst.props?.props || {} + } + } const app = (isNewBlended ? nativeComponentApp : Current.app) if (!app) { initNativeComponentEntry({