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>
相关推荐
工一木子36 分钟前
URL时间戳参数深度解析:缓存破坏与前端优化的前世今生
前端·缓存
半点寒12W2 小时前
微信小程序实现路由拦截的方法
前端
某公司摸鱼前端3 小时前
uniapp socket 封装 (可拿去直接用)
前端·javascript·websocket·uni-app
要加油哦~3 小时前
vue | 插件 | 移动文件的插件 —— move-file-cli 插件 的安装与使用
前端·javascript·vue.js
小林学习编程3 小时前
Springboot + vue + uni-app小程序web端全套家具商场
前端·vue.js·spring boot
柳鲲鹏3 小时前
WINDOWS最快布署WEB服务器:apache2
服务器·前端·windows
weixin-a153003083164 小时前
【playwright篇】教程(十七)[html元素知识]
java·前端·html
ai小鬼头5 小时前
AIStarter最新版怎么卸载AI项目?一键删除操作指南(附路径设置技巧)
前端·后端·github
一只叫煤球的猫5 小时前
普通程序员,从开发到管理岗,为什么我越升职越痛苦?
前端·后端·全栈
vvilkim5 小时前
Electron 自动更新机制详解:实现无缝应用升级
前端·javascript·electron