Javascript 该映射在转到页面开始时不起作用,但在vuejs中刷新页面时起作用

Javascript 该映射在转到页面开始时不起作用,但在vuejs中刷新页面时起作用,javascript,vue.js,Javascript,Vue.js,该映射在转到页面开始时不起作用,但在Vue.js中刷新页面时起作用 在这件事上有什么帮助吗 此代码 mounted() { this.geolocate(); }, methods: { async geolocate() { this.getFloatDirections(); this.center = { lat: this.lat, lng: this.lng };

该映射在转到页面开始时不起作用,但在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;
    }
}
请在刷新之前删除此图像

刷新后,将显示此图像

created()替换
mounted()

装载DOM后调用
mounted()
,以便您可以访问反应组件、模板和DOM元素并对其进行操作

如果您需要了解有关vue的更多信息。

已安装的()
替换为
已创建的()

装载DOM后调用
mounted()
,以便您可以访问反应组件、模板和DOM元素并对其进行操作


如果您需要了解有关vue的更多信息。

请尝试使用
created
hook而不是
mounted
。刷新相当于重新加载组件尝试使用
创建的
钩子而不是
挂载的
。刷新相当于重新渲染组件