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

setState的异步问题 #595

Closed
funky-tiger opened this issue Sep 8, 2018 · 2 comments
Closed

setState的异步问题 #595

funky-tiger opened this issue Sep 8, 2018 · 2 comments
Labels
question Further information is requested

Comments

@funky-tiger
Copy link

问题描述
[问题描述:setState的异步更新数据 导致页面没有及时刷新
复现步骤
1 页面onPageScroll监滚动实现fixed定位

2 当达到滚动条件时setState一个变量为true

3 setState一个变量为true时实现fixed固定定位

4 因为setState的异步问题 即使执行了setSate 页面也不会立即更新 导致需要滚动多次才能实现fixed定位

if (e.scrollTop >= this.state.chose_scroll_top){

      this.setState({isFixed:true})

    }else{

      this.setState({ isFixed: false })

    }

期望行为
期望setState后立即更新视图 实现fixed定位

报错信息
无报错

系统信息

  • 操作系统: [e.g. Windows 10]
  • Taro 版本 [e.g. v1.0.0-beta.22]
  • Node.js 版本 [e.g. v8.11.3]

补充信息
根据是setState异步刷新数据的问题 而且根据我的需求 我也不能在setState里面的回调函数里面去写逻辑

@luckyadam
Copy link
Member

setState 虽然是异步的,但是会去更新视图,这里在滚动里不停 setState 的方式不推荐,建议考虑别的写法

@yuche yuche added question Further information is requested answered labels Nov 1, 2018
@taro-bot taro-bot bot added the to be closed label Nov 8, 2018
@taro-bot
Copy link

taro-bot bot commented Nov 8, 2018

Hello~

您的问题楼上已经有了确切的回答,如果没有更多的问题这个 issue 将在 15 天后被自动关闭。

如果您在这 15 天中更新更多信息自动关闭的流程会自动取消,如有其他问题也可以发起新的 Issue。

Good luck and happy coding~

@taro-bot taro-bot bot removed the to be closed label Nov 23, 2018
@taro-bot taro-bot bot closed this as completed Nov 23, 2018
xiaoyan428820 pushed a commit to xiaoyan428820/taro that referenced this issue Jun 18, 2024
…3.6.29-liuyang

解决容器共用时,Taro的navigate和原生loadUrl混用问题
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants