vue引入高德地图问题

<script>
let posX = 116.397428;
let posY = 39.90923;
export default {
    data () {
        return {

        }
    },
    methods:{
        clickMe(){
            console.log(111);
            posY = 38.90923;
            this.loadMap();
        },
        //初始化地图
        initMap(){
            var scriptUrl = `https://webapi.amap.com/maps?v=1.4.13&key=b6669f90789f2971b0a439ce5ff64dd3&callback=map_callback`
            var scriptID = 'map_amp_ID'
            if(window.scriptID){
                window.map_callback()
                console.log('已加载成功')
                return
            }
            var script = document.createElement('script')
            script.id = scriptID
            script.src = scriptUrl

            var amapUIJs = document.createElement('script')
            amapUIJs.src = 'https://webapi.amap.com/ui/1.0/main-async.js'

            document.body.appendChild(script)
            document.body.appendChild(amapUIJs)
        },
        //加载地图
        loadMap(){
            var map = new AMap.Map('container', {
                zoom:16,//级别
                center: [posX,posY],//中心点坐标
            });
            var marker = new AMap.Marker({
                position:[posX,posY]//位置
            });
            map.add(marker);//添加到地图
        }
    },
    mounted:function(){
        //地图回调
        window.map_callback = this.loadMap();
    },
    created:function(){
        this.initMap();
    }
}
</script>

clipboard.png

报了一个错,怎么回事

阅读 4.4k
2 个回答
推荐问题
宣传栏