Skip to content
New issue

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

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

Already on GitHub? # to your account

function组件中如何使用 getOpenerEventChannel #7066

Closed
without-yy opened this issue Jul 15, 2020 · 8 comments
Closed

function组件中如何使用 getOpenerEventChannel #7066

without-yy opened this issue Jul 15, 2020 · 8 comments
Labels
enhancement New feature or request

Comments

@without-yy
Copy link

这个特性解决了什么问题?

下级页面往上级页面传递数据

这个 API 长什么样?

类似于 useDispatch ??

@taro-bot2 taro-bot2 bot added the enhancement New feature or request label Jul 15, 2020
@zxtyjx
Copy link

zxtyjx commented Jul 15, 2020

同问 在hooks中怎么使用getOpenerEventChannel这个函数想来源页面传值

@without-yy
Copy link
Author

暂时用这个方法可以获取到eventChannel

const pages =getCurrentPages();
const current = pages[pages.length - 1];
const eventChannel = current.getOpenerEventChannel();

@zxtyjx
Copy link

zxtyjx commented Jul 15, 2020

可以找到这个方法了,但是获取到的eventChannel是个空对象,你这边是这个情况吗

@zxtyjx
Copy link

zxtyjx commented Jul 15, 2020

是因为调用getOpenerEventChannel()方法时报了[data is not defined]这个错误,我分别在useReady、useLayoutEffect、useEffect这三个生命周期中调用报的错误相同,有人遇到相同的问题吗?

@without-yy
Copy link
Author

@zxtyjx 我在useEffect中可以获取成功

AFr16S5qRjkxwLH
u8yoiZMmfaxOjJK

@Chen-jj
Copy link
Contributor

Chen-jj commented Jul 16, 2020

@Chen-jj Chen-jj closed this as completed Jul 16, 2020
@cuiyajie
Copy link

cuiyajie commented Aug 4, 2020

when use the Taro.eventCenter, the event was triggered in navigateTo's callback which was done before the event listener was registered in target page componentDidMount. Hence event listener will not run when entering the page first.

@lifegit
Copy link

lifegit commented Jan 23, 2021

#7903

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants