uniapp返回webview返回小程序并且跳转回webview

webview页面

提示:wx一定要导入sdk

// 返回小程序,并携带当前 WebView 的 URL 和状态

wx.miniProgram.postMessage({

type: 'requestPayment',

data: {

webviewUrl: window.location.href,

orderNum: this.orderNum,

type: 'requestPayment'

}

})

setTimeout(() => {

wx.miniProgram.navigateBack({

delta: 1,

});

}, 300);

小程序webview

<template>

<view>

<web-view

:key="webviewKey"

:src="url"

@message="onWebMessage"

@onPostMessage="onPostMessage"

></web-view>

</view>

</template>

<script>

export default {

data() {

return {

url: "",

webviewKey: ''

};

},

onLoad(options) {

console.log(options);

//this.url = options.url

if (options.url) {

this.url = decodeURIComponent(options.url);

}

if(options.token){

uni.setStorageSync('token',options.token)

}

console.log("-----------", this.url);

},

onShow(e) {

},

methods: {

onWebMessage(e) {

let list = e.detail.data;

let payFlag = list.find((v)=>{

return v.type == "requestPayment"

})

if(payFlag){

this.payFun(payFlag);

}

console.log("onWebMessage", e);

},

// 支付方法

payFun(params){

},

onPostMessage(e) {

console.log("onPostMessage", e);

},

},

};

</script>

<style></style>

相关推荐
土土哥V_araolin11 小时前
双迹美业模式系统开发(现成源码)
小程序·个人开发·零售
2501_9339072118 小时前
南京本凡科技,怎么选择专业小程序开发才能提升品牌竞争力?
科技·微信小程序·小程序
笨笨狗吞噬者19 小时前
维护 uniapp 小程序端近一年,我想拉一个开发者交流群
前端·程序员·uni-app
2501_9339072121 小时前
本凡科技提供的宁波小程序开发服务全面解决方案
科技·微信小程序·小程序
左师佑图21 小时前
微信小程序集成 Day.js 插件的完整解决方案
微信小程序·小程序
2501_933907211 天前
本凡科技提供宁波小程序服务与定制解决方案
科技·微信小程序·小程序
计算机徐师兄1 天前
Java基于SpringBoot的运动健康小程序【附源码、文档说明】
spring boot·小程序·运动健康·java运动健康小程序·运动健康小程序·java运动健康微信小程序·运动健康微信小程序
Xpower 171 天前
OpenClaw实战:从零开发电商小程序(2)
人工智能·语言模型·小程序·gateway
2501_933907211 天前
宁波小程序开发服务与技术团队专业支持
科技·微信小程序·小程序
sheji34162 天前
【开题答辩全过程】以 基于微信小程序的少儿编程学习平台为例,包含答辩的问题和答案
学习·微信小程序·小程序