地图在开始进入页面时不起作用,但如果在vuejs中刷新页面时起作用。

问题描述 投票:0回答:1

地图不工作在开始进入页面,但在Vue.js中刷新页面时工作。

有任何帮助在这个问题上?

这段代码

mounted() { 
    this.geolocate();
},
methods: {

    async geolocate() {
        this.getFloatDirections();
        this.center = {
            lat: this.lat,
            lng: this.lng
        };
        this.coordinates = {
            full_name: this.$route.query.name,
            lat: this.lat,
            lng: this.lng
        };
        // console.log("typeof(this.center.lat)"+typeof(this.$route.params.lat))
    },
    getFloatDirections(){
        this.lat = parseFloat(this.$route.params.lat);
        this.lng = parseFloat(this.$route.params.lng);
    },
    getPosition: function(marker) {
        return {
            lat: marker.lat,
            lng: marker.lng
        };
    },
    toggleInfo: function(marker) {
        this.infoPosition = this.getPosition(marker);
        this.infoContent = marker.full_name;

        this.infoOpened = true;
    }
}

此图刷新前before refresh

此图刷新后

after refresh

javascript vue.js
1个回答
0
投票

替换 mounted()created()

mounted() 是在DOM被挂载后调用的,这样你就可以访问反应式组件、模板和DOM元素并对它们进行操作。

如果你需要了解更多关于vue 生命周期挂钩.

© www.soinside.com 2019 - 2024. All rights reserved.