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

uniapp App页面通过 web-view 调用网页内方法

先是报这个错

A parser-blocking, cross site (i.e. different eTLD+1) script, https://api.map.baidu.com/getscript?v=3.0&ak=pgJsRF87Fjia&services=&t=20250225111334, is invoked via document.write. The network request for this script MAY be blocked by the browser in this or a future page load due to poor network connectivity. If blocked in this page load, it will be confirmed in a subsequent console message. See https://www.chromestatus.com/feature/5718547946799104 for more details. at https://api.map.baidu.com/api?v=3.0&ak=p1Ona:1
17:44:49.105 [WARNING] :A parser-blocking, cross site (i.e. different eTLD+1) script, https://api.map.baidu.com/getscript?v=3.0&ak=p1O7Fjia&services=&t=20250225111334, is invoked via document.write. The network request for this script MAY be blocked by the browser in this or a future page load due to poor network connectivity. If blocked in this page load, it will be confirmed in a subsequent console message. See https://www.chromestatus.com/feature/5718547946799104 for more details. at https://api.map.baidu.com/api?v=3.0&ak=p1On6Mpgs8yRrLU7RRgJsRF87Fjia:1
17:44:49.274 [HMR] Waiting for update signal from WDS... at http://192.168.1.95:9091/static/js/chunk-vendors.js:15242
17:44:49.790 Download the Vue Devtools extension for a better development experience:
https://github.com/vuejs/vue-devtools at http://192.168.1.95:9091/static/js/chunk-vendors.js:49249

排查发现可能是 

https://api.map.baidu.com/getscript?v=3.0&ak=p1On6Mpgs8yRR7U7RRgJsRF87Fjia&services=&t=20250225111334

这个js加载太慢 终止了 document.write 调用的js,把这个js文件引入先去掉就可以了

<template>
	<view>
		<button  @click="sendMessage" style="z-index: 999999;height: 50px;">Send Message</button>
		<web-view ref="webview" src="http://192.168.1.95:9091/#/pages/index" style="height: 400px;margin-top: 50px;"></web-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
			}
		},
		methods: {
			sendMessage() {
				//this.$refs.webview.evalJs(`alert('Message from UniApp')`);
				const currentWebview = this.$scope.$getAppWebview();
				const wv = currentWebview.children()[0];
				wv.evalJS(`alert('Message from UniApp')`);
			},
		},
		onReady() {
		    // 确保 web-view 已加载完成
		    setTimeout(() => {
		      this.sendMessage();
		    }, 3000);
		  },
	}
</script>

<style>

</style>

相关文章:

  • 协方差相关问题
  • 前后端接口参数详解与 Mock 配置指南【大模型总结】
  • 区块链知识点4
  • 学透Spring Boot — 015. 自废武功——关闭自动配置
  • Ubunut18.04 离线安装MySQL 5.7.35
  • Vue3 路由权限管理:基于角色的路由生成与访问控制
  • YOLOv1学习笔记
  • 2. Qt界面文件原理
  • Java面向对象编程详解
  • VUE中的CompositionAPI绑定
  • leetcode274.H指数
  • Java 知识点汇总(三)
  • Android Compose 中获取和使用 Context 的完整指南
  • 数字人分身源码搭建:支持OEM
  • 浅谈「分词」:原理 + 方案对比 + 最佳实践
  • c语言常见类型的范围到底是啥?
  • Ubertool 的详细介绍、安装指南及使用说明
  • 垃圾回收——三色标记法(golang使用)
  • python Socket编程
  • 典型的ETL使用场景与数据集成平台的应用
  • 国外网站开发公司/广告公司品牌营销推广
  • 个人简历模板word可编辑免费/优化的定义
  • qq空间怎么做网站/国家卫健委最新疫情报告
  • 极简wordpress主题/网站外链优化方法
  • 高端网站设计元素图片/安仁网络推广
  • 做网站大公司有哪些/seo站长综合查询