Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zzefff opened this issue Nov 23, 2023 · 0 comments
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@zzefff
Copy link

zzefff commented Nov 23, 2023

相关平台

微信小程序

小程序基础库: 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 

@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
Status: Todo
Development

No branches or pull requests

1 participant