taro icon indicating copy to clipboard operation
taro copied to clipboard

微信小程序启动打开原生页面调用原生getApp()无法返回taroGlobalData,如何修改?

Open zzefff opened this issue 1 year ago • 1 comments

相关平台

微信小程序

小程序基础库: 2.30.2 使用框架: React

复现步骤

// app.tsx
class App extends React.Component {
  componentDidMount() {}
  taroGlobalData = { test: 123}
  ...
}

// some native wx page: pages/SomeWxPage/SomeWxPage.js
Page({
  onLoad() {
        console.log(getApp().test) // undefined
  }
})

如果用户 直接启动小程序 打开 pages/SomeWxPage/SomeWxPage,就会报错。

期望结果

getApp().test 预期取到 123。另外希望指导下原生页面获取taroGlobalData的正确方法

实际结果

getApp().test 得到 undefined

环境信息

Taro v3.5.12


  Taro CLI 3.5.12 environment info:
    System:
      OS: macOS 12.6.8
      Shell: 5.8.1 - /bin/zsh
    Binaries:
      Node: 18.15.0 - ~/.nvm/versions/node/v18.15.0/bin/node
      Yarn: 1.22.19 - ~/.nvm/versions/node/v18.15.0/bin/yarn
      npm: 9.5.0 - ~/.nvm/versions/node/v18.15.0/bin/npm
    npmPackages:
      @tarojs/cli: 3.5.12 => 3.5.12 
      @tarojs/components: 3.5.12 => 3.5.12 
      @tarojs/helper: 3.5.12 => 3.5.12 
      @tarojs/plugin-framework-react: 3.5.12 => 3.5.12 
      @tarojs/plugin-platform-alipay: 3.5.12 => 3.5.12 
      @tarojs/plugin-platform-jd: 3.5.12 => 3.5.12 
      @tarojs/plugin-platform-qq: 3.5.12 => 3.5.12 
      @tarojs/plugin-platform-swan: 3.5.12 => 3.5.12 
      @tarojs/plugin-platform-tt: 3.5.12 => 3.5.12 
      @tarojs/plugin-platform-weapp: 3.5.12 => 3.5.12 
      @tarojs/react: 3.5.12 => 3.5.12 
      @tarojs/router: 3.5.12 => 3.5.12 
      @tarojs/runtime: 3.5.12 => 3.5.12 
      @tarojs/shared: 3.5.12 => 3.5.12 
      @tarojs/taro: 3.5.12 => 3.5.12 
      @tarojs/taro-h5: 3.5.12 => 3.5.12 
      @tarojs/webpack5-runner: 3.5.12 => 3.5.12 
      babel-preset-taro: 3.5.12 => 3.5.12 
      eslint-config-taro: 3.5.12 => 3.5.12 
      react: ^18.0.0 => 18.2.0 

zzefff avatar Nov 23 '23 05:11 zzefff