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

await Taro.request(params)无效,根本就不是同步的 #9059

Closed
shijunti19 opened this issue Apr 8, 2021 · 7 comments
Closed

await Taro.request(params)无效,根本就不是同步的 #9059

shijunti19 opened this issue Apr 8, 2021 · 7 comments
Labels
F-react Framework - React T-h5 Target - 编译到 H5 V-3 Version - 3.x

Comments

@shijunti19
Copy link

shijunti19 commented Apr 8, 2021

相关平台

H5

浏览器版本: Chrome 89.0.4389.114
使用框架: vue3

复现步骤

直接写下就行
image
image

期望结果

测试1
测试2
测试3
这样先输出

实际结果

测试1
测试2
然后其他的信息
测试3
这是异步的结果啊

环境信息

👽 Taro v3.2.0


  Taro CLI 3.2.0 environment info:
    System:
      OS: Windows 10
    Binaries:
      Node: 15.12.0 - E:\Program Files\nodejs\node.EXE
      Yarn: 1.23.0-20200224.1838 - E:\Program Files\Yarn\bin\yarn.CMD
      npm: 6.14.8 - E:\Program Files\nodejs\npm.CMD
@taro-bot2 taro-bot2 bot added F-react Framework - React T-h5 Target - 编译到 H5 V-3 Version - 3.x labels Apr 8, 2021
@Wind4
Copy link

Wind4 commented Apr 8, 2021

你这个结果符合预期呀!await 之后js线程就先去执行别的任务了,等 Request 回来之后再继续执行 await 之后的内容。

@shijunti19
Copy link
Author

shijunti19 commented Apr 8, 2021

@Wind4 本地有token了,然后我需要拉取token的会员信息,存到store,如果有就显示本页不然跳到登录。就是页面登录判断
按这个逻辑 ,我办不到了,刷新页面store永远都是空的啊

我只能判断本地是否有token这个去判断了,但是他会过期

我怎么做路由守卫拦截,vue3里,没找到好的办法啊!没登录不准进页面的

@Wind4
Copy link

Wind4 commented Apr 8, 2021

因为在小程序中无法阻止跳转到Page,所以你只能在Page的onLoad里面处理登录请求。

我们目前有两种处理方式:

  1. 新建一个InitPage处理登录会话,等登录请求成功之后在replace跳到目标页。
  2. 封装Request中间件,在请求出去之前拦截下来,先获取更新登录token,然后再放行请求

token过期我们会通过statusCode=401来触发更新token

@shijunti19
Copy link
Author

@Wind4 好的,这样的结果就是会跳动下

@shijunti19 shijunti19 reopened this Apr 8, 2021
@shijunti19
Copy link
Author

@Wind4 还有个问题,我在/pages/user/index/index有个tab_bar,有个跳转 Taro.navigateTo({
url: '/pages/user/index/index',
});
这个跳转后页面空白,自己跳自己怎么会空白!!

@Wind4
Copy link

Wind4 commented Apr 8, 2021

Tab页要用 switchTab 吧?

@shijunti19
Copy link
Author

shijunti19 commented Apr 8, 2021

@Wind4 不是,是https://b2nil.github.io/taro-ui-vue3/docs/tabbar.html
这个的,他不需要,他和微信的重复的,我用的ui的,h5里会出现空白,很奇怪,我觉得他本身要判断下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-h5 Target - 编译到 H5 V-3 Version - 3.x
Projects
Archived in project
Development

No branches or pull requests

2 participants