webview---小程序-----webivew 返回时如何同步状态?

小程序 文章 2021-03-06 16:41 481 0 全屏看文

AI助手支持GPT4.0

webview---小程序-----webivew 返回时如何同步状态?webview---small program-----how to synchronize the status when webivew returns?

webview---小程序-----webivew 返回时如何同步状态?

在微信小程序中的webview页面A,使用wx.navigateTo跳转到小程序页面B,在小程序页面B上完成一键登录逻辑完了之后携带参数跳转到webview页面C,这时候webview页面C请求一个接口完成后要逐步返回到webview页面A,页面A的状态不会同步,无法拿到刚才页面C的接口里的数据,要怎么让它同步?

1.如果去刷新webview页面A,要怎么刷新,我目前尝试了网上的刷新方案,总是会刷新到页面C上,而不是A

2.如果在页面B返回A时携带参数,要怎么携带,目前使用wx.navigateBack来返回

In the WebView page a of wechat applet, use wx.navigateTo Jump to applet page B. after completing one click login logic on applet page B, jump to WebView page C with parameters. At this time, WebView page C requests an interface, and then returns to WebView page a step by step. The status of page a will not be synchronized, and the data in the interface of just started page C cannot be obtained, How do you synchronize it? 1. If I want to refresh WebView page a, how do I refresh? I have tried the online refresh scheme, and I always refresh to page C instead of page A. 2. If I carry parameters when page B returns to a, how do I carry them wx.navigateBack Come back

回答:

🙄:
小程序页面B ==》 webview页面A    可以在url带上参数  wx.navigateTo({url: '/pages/webview?参数'})  如果有这个参数就刷新呗


#&&key=.:

可以用this.options来获取小程序页面中的参数,然后a页面通过传入的参数来进入指定的页面,代码大概像下面这样

js

data: {    src:''  // 这里填写页面默认的地址  },  onLoad: function (options) {    console.log(options);    if(options && options.src != undefined){          let src = decodeURIComponent(options.src);      src = src.replace(/http:///, "https://");      this.setData({        src: src      })    }  },


wxml

<web-view src="/uploads/cj/article/2021/03/06/95ef2cfb3513bcae15d4c665c58c0a54.jpg"></web-view>


在b页面登录获取参数后,用wx.reLaunch来进入a页面,参数传在src内,注意需要encode下哦!

wx.reLaunch({	url: '/pages/index/index?src=' + src,})
詹迪克:

页面A wx.redirect -》 页面B wx.redirect 页面C -》wx.redirect +参数至 页面A

-EOF-

AI助手支持GPT4.0