美文网首页
Vue cdn引入百度地图导致的页面滚动问题

Vue cdn引入百度地图导致的页面滚动问题

作者: fordG | 来源:发表于2021-11-12 08:58 被阅读0次
    loadBMap() {
            return new Promise(function(resolve, reject) {
                if (typeof window.BMap !== 'undefined') {
                                    setTimeout(e=>{
                        //百度地图加载之后导致页面可滚动问题
                        let iframe = document.body.childNodes[document.body.childNodes.length -1];
                        document.body.removeChild(iframe);
                    },1000);
                    resolve(window.BMap)
                    return true
                }
                window.onBMapCallback = function() {
                    resolve(window.BMap)
                }
                let script = document.createElement('script')
                script.type = 'text/javascript'
                script.src =
                    'http://api.map.baidu.com/api?v=3.0&ak=7RMy465oWLk4VlLGTkMG7sVSXU4zt1LP&callback=onBMapCallback'
                script.onerror = reject
                document.head.appendChild(script)
            })
        },
    
        location(success, faile) {
            this.loadBMap().then(BMap => {
                setTimeout(e=>{
                    //百度地图加载之后导致页面可滚动问题
                    let iframe = document.body.childNodes[document.body.childNodes.length -1];
                    document.body.removeChild(iframe);
                },1000);
                try {
                    var geolocation = new BMap.Geolocation();
                    geolocation.getCurrentPosition(function(r) {
                        if (this.getStatus() == BMAP_STATUS_SUCCESS) {
                            success(r.point);
                        } else {
                            faile(this.getStatus());
                        }
                    });
                } catch (e) {
                    Vue.prototype.$throw(JSON.stringify(e));
                    faile(e)
                }
            }).catch(error => {
                Vue.prototype.$throw(JSON.stringify(error));
                faile(error)
            })
        },
    

    相关文章

      网友评论

          本文标题:Vue cdn引入百度地图导致的页面滚动问题

          本文链接:https://www.haomeiwen.com/subject/fsmnzltx.html