当前位置: 首页 > news >正文

uniapp小程序使用webview 嵌套 vue 项目

uniapp小程序使用webview 嵌套 vue 项目

小程序中发送

<web-view :src="urlSrc" @message="handleMessage"></web-view>export default {data() {return {urlSrc: "",};},onLoad(options) {// 我需要的参数比较多 所以比较臃肿// 获取用户信息 根据自己需要let userInfor = uni.getStorageSync("userInfor") || ''// web-view urlthis.urlSrc = "https://xxxxxxxx.com/#/viewsEdit?key=" + options.id + "&srcurl=viewsEdit" +"&token=" + uni.getStorageSync('token') + "&wxopenid=" + uni.getStorageSync('wxopenid') + '&phone=' + userInfor.mobilePhone + "&name=" + userInfor.nickName + "&surveyId=" + options.ids}}

vue中接收参数

// index.html 中引入<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
// App.vue中<template><div id="app"><RouterView v-if="isRouterAlive" /></div>
</template><script>
export default {mounted() {// 主要代码 开始let that = thisconsole.log(window.location, 'this.$router.query')// 获取url 中的参数let datas = that.getUrlParams(window.location.href)if (datas.token) {// 保存tokenthat.$store.dispatch('user/login', {token: 'bearer' + datas.token,...datas}).then(() => {// 登录成功后路由跳回that.$router.replace({path: '/viewsEdit',query: {key: datas.key,wxopenid:datas.wxopenid,phone:datas.phone,name:datas.name,surveyId:datas.surveyId,}})})},methods: {getUrlParams(url) {const params = {}const reg = /([^?&=]+)=([^&]*)/gurl.replace(reg, (match, key, value) => {params[decodeURIComponent(key)] = decodeURIComponent(value)})return params},}
}
</script>
// 使用uni提供的webview.js插件跳转小程序的页面
npm i uni-webview-lib 

vue发送消息给uniapp

//   viewsEdit.vue
<template><div @click="submitForm">去小程序</div>
</template><script>
import {createFormResultRequest,
} from '@/api/project/data'
import uni from 'uni-webview-lib'
export default {methods: {submitForm() {createFormResultRequest().then((res) => {const message = '参数'uni.reLaunch({// 带上需要传递的参数url: `/subFishingBay/pages/palaceDraw/luckdraw?message=${message}&id=${res.data.id}`})this.msgSuccess('添加成功')})}}
}
</script>

小程序中接收数据

	 // 在上面跳转的页面  /subFishingBay/pages/palaceDraw/luckdraw// luckdraw.vueonLoad(options) {console.log(options,'这里是传过来的参数')},

搞定!

http://www.lryc.cn/news/397100.html

相关文章:

  • 命令模式在金融业务中的应用及其框架实现
  • WordPress的性能优化有哪些方法?
  • 【Python基础】代码如何打包成exe可执行文件
  • Golang | Leetcode Golang题解之第227题基本计算器II
  • 云端美味:iCloud中食谱与餐饮计划的智能存储方案
  • leetcode:1332. 删除回文子序列(python3解法)
  • 智慧交通的神经中枢:Transformer模型在智能交通系统中的应用
  • PCIe驱动开发(1)— 开发环境搭建
  • YOLOv10改进 | Conv篇 | CVPR2024最新DynamicConv替换下采样(解决低FLOPs陷阱)
  • 变革设计领域:Transformer模型在智能辅助设计中的革命性应用
  • Spring——配置说明
  • 禁用华为小米?微软中国免费送iPhone15
  • nginx初理解
  • FreeCAD源码分析:属性系统
  • C++入门 模仿mysql控制台输出表格
  • SpringBoot新手快速入门系列教程五:基于JPA的一个Mysql简单读写例子
  • 开源大势所趋
  • 智能无人机飞行控制系统:基于STM32的设计与实现(内附资料)
  • centos磁盘空间满了-问题解决
  • 宝塔:如何开启面板ssl并更新过期ssl
  • 大白话讲解AI大模型
  • pandas+pywin32操作excel办公自动化
  • 防火墙(ensp USG6000v)---安全策略 + 用户认证综合实验
  • Java使用POI导出后数字类型为常规类型,不能计算
  • 项目进度管理(5-1)常见的缓冲区监控方法
  • 构造函数语意学(The Semantics of Constructors)
  • 香橙派5plus上跑云手机方案二 waydroid
  • 600Kg大载重起飞重量多旋翼无人机技术详解
  • LlamaFactory可视化微调大模型 - 参数详解
  • 最新 Kubernetes 集群部署 + flannel 网络插件(保姆级教程,最新 K8S 版本)