VUE中初始化高德地图时机问题

created中初始化地图显示一片黄。。。

mounted中初始化地图正常显示。

<style>
	#vueForm, #container{
		width:500px;
		height:500px;
	}
</style>

<div id="vueForm">

	<div id="container"></div>
    
</div>

<script>
    new Vue({
        el: '#vueForm',
        data: function() {
            return {
                
            };
        },
        methods: {
            initMap: function() {
                var longitude = '';
                var latitude = '';
                if(longitude == ''){
                    longitude = 116.397428;
                }
                if(latitude == ''){
                    latitude = 39.90923;
                }
                var center = [longitude, latitude];
                var map = new AMap.Map('container', {
                    resizeEnable: true,
                    zoom: 16,
                    scrollWheel: false,
                    center:center
                })
            }
        },
        created: function() {
            // this.initMap();
        },
        mounted: function() {
            this.initMap();
        }
    });
</script>
发布了79 篇原创文章 · 获赞 40 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/u013727805/article/details/104174704