使用场景
在vue2项目中使用 new Loca.LinkLayer 时通过index.html脚本引入,首次切换到当前页面时loca模块未加载导致无法使用此功能报错为: Loca.LinkLayer is not a constructor 重新刷新当前页面才正常使用,解决方案为Vue组件内部动态加载脚本,确保脚本加载逻辑放在组件的mounted钩子中或者在需要时手动触发加载
mounted() {
const script = document.createElement('script');
script.src = '//webapi.amap.com/loca?v=1.3.2&key=xxxxxxxxx';
document.head.appendChild(script);
}