高德地图JSAPI报错:[Violation] 'requestAnimationFrame' handler took 125ms


先说下我遇到的问题,vue3中使用高德地图绘制线路的时候,很卡掉帧,还报警告[Violation] ‘requestAnimationFrame’ handler took 125ms。

解决方法就是不把map实例存到reactive或者ref中,使用shallowRef来存。

之前我是这样写的:

const dataContainer = reactive({
    mouseTool: null,
    map: null
});
function initMap() {
    dataContainer.map = new AMap.Map("map", {
        center: [116.434381, 39.898515],
        zoom: 14
    });
    dataContainer.mouseTool= new AMap.MouseTool(dataContainer.map);
}

修改后:

import { shallowRef } from 'vue';

const mapContainer = shallowRef(null);
const mouseToolContainer = shallowRef(null);

function initMap() { 
    mapContainer.value = new AMap.Map("map", {
      center: [116.434381, 39.898515],
      zoom: 14
    });
    mouseToolContainer.value = new AMap.MouseTool(mapContainer.value);
 }
Logo

分享最新的 NVIDIA AI Software 资源以及活动/会议信息,精选收录AI相关技术内容,欢迎大家加入社区并参与讨论。

更多推荐