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>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章