javascript - postMessage 总是返回错误的数据?
问题描述
我的目标是单击当前选项卡中的一个按钮,它将打开一个新选项卡,并在新选项卡的 Chrome 开发工具中使用 postMessage API:
window.opener.postMessage({deliveryId: 18042548, materialId: 1051041576634029702},'*')
当前选项卡已经添加了onmessage
事件,它将检查来源,console.log
数据:
window.addEventListener("message", this.syncDirectMaterialTag)
syncDirectMaterialTag = async e => {
if ('http://beta-ace.jd.com' === e.origin) {
console.log(e.data)
//const res = await queryDirMaterialTag(mapper)
}
}
但无论我发布什么,它总是返回相同的错误信息:
deliveryId: 18042548
materialId: 1051041576634029700
怎么会这样 ???
解决方案
我已经修好了。
原因是 JavaScript 失去了准确性。
所以materialId的类型应该是String:
window.opener.postMessage({deliveryId: 18042548, materialId: '1051041576634029702'},'*')
推荐阅读
- javascript - 绑定数组的对象数组
- android - CardViews 未显示在 RecyclerView 中
- sql - 列被随机删除Postgres?
- c# - 检测 .NET Framework 功能和 WCF 服务
- r - 不同目录中的同时 R 会话
- javascript - Angular 6如何在表单内制作所有输入的不可编辑元素
- java - 是否可以创建一个哈希映射,其中每个值都是对对象有不同作用的方法
- windows-7 - 是否可以使用 Windows cmd 在 Notepad++ 中输入 SecurePad 插件的密码?[编辑]
- eclipse - 从 Github 父/子 pom 在 Eclipse 中创建新项目?
- python - 带有大数据的 Seaborn 直方图