Skip to content

Commit

Permalink
fix: 百度小程序 不支持模版传递函数参数 同时在真机时 它把函数改成了空对象 (#15923)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiqingchen authored Jul 12, 2024
1 parent 7f20946 commit 99a9d8b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/taro-plugin-react/src/runtime/connect-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 99a9d8b

Please sign in to comment.