1***@qq.com
1***@qq.com
  • 发布:2025-02-11 20:08
  • 更新:2025-02-12 10:39
  • 阅读:41

【报Bug】uniapp vue2 在vue页面web-view 动态加载谷歌地图 并添加高级标记时,报错this.Mi.replaceChildren is not a function

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: windows10

HBuilderX类型: 正式

HBuilderX版本号: 4.29

手机系统: Android

手机系统版本号: Android 10

手机厂商: vivo

手机机型: vivos7e

页面类型: vue

vue版本: vue3

打包方式: 离线

项目创建方式: HBuilderX

操作步骤:
        async function initMap() {  
            const { Map} = await google.maps.importLibrary("maps");  
            const { AdvancedMarkerElement,PinElement } = await google.maps.importLibrary("marker");  

            let map = new Map(document.getElementById('container'), {  
                center: {  
                    lat: -25.363,  
                    lng: 131.044  
                },  
                zoom: 15, //地图缩放比例  
                mapId: "DEMO_MAP_ID"  
            }); // 创建地图实例  
            const pinBackground = new PinElement({  
                background: '#FFFFFF',  
             });  
            const marker = new AdvancedMarkerElement ({  
                map,  
                position: {  
                    lat: -25.363,  
                    lng: 131.044,  
                },  
                content:imgItem  
            });  
        }  
    initMap();

预期结果:

正常添加谷歌地图高级标记

实际结果:

报错

bug描述:

uniapp vue3 ,在index.vue 页面的 web-view 加载 本地html,html 使用 谷歌地图weekly版本 ,并添加 高级标记时 报错:this.Mi.replaceChildren is not a function 。谷歌地图beta 版本添加高级标记时报错:this.replaceChildren is not a function 。但此html 在web 端直接看,是正常的。这个有什么解决办法吗?

2025-02-11 20:08 负责人:无 分享
已邀请:
1***@qq.com

1***@qq.com (作者)

标题写错了是vue3

1***@qq.com

1***@qq.com (作者)

vue3 语言vue 页面,web-view加载html 后,运行到app

const parentElement = document.getElementById('myElement');  
const newElement = document.createElement('p');  
newElement.textContent = 'New content';  
console.log(JSON.stringify(newElement));  
 parentElement.replaceChildren(newElement);

也报错 parentElement.replaceChildren is not a function 。但在web 端正常。 有什么解决办法吗?如何在html 中加入replaceChildren这个方法呢?

1***@qq.com

1***@qq.com (作者)

找到方法啦!!!!!!!!!!!!!
在html 中<scritp>顶部加入

<script>  
        (function() {  
          if (!Element.prototype.replaceChildren) {  
            Element.prototype.replaceChildren = function(...nodes) {  
              this.innerHTML = ''; // 清空当前元素的所有子节点  
              for (let node of nodes) {  
                this.appendChild(node); // 添加新的子节点  
              }  
            };  
          }  
        })();  
........................................  

之后再写别的就可以用啦!!!!!!!!!!!!!!

要回复问题请先登录注册