每次调用 esri-loader 的包都须要去引入,就很麻烦
偶尔发现的新鲜写法
import {loadModules} from "esri-loader";
// 配置 arcgis 中各个包与绝对应的门路
const __arcgisUrl = {
MapView: "esri/views/MapView",
Map: "esri/Map",
};
// 不暴漏在外的存储对象
const __arcgis = {};
// 定义裸露的 arcgis 变量
const arcgisPackage = new Proxy({},
{
// 拦挡取值
async get(target, key) {// console.log(key, receiver);
// console.log(config);
let val = {};
if (typeof __arcgis[key] === "undefined") {[val] = await loadModules([__arcgisUrl[key]], {
url: "http://***.***.***.***:8686/415/init.js",
dojoConfig: {baseUrl: "http://***.***.***.***:8686/415/dojo",},
});
__arcgis[key] = val;
} else {val = __arcgis[key];
}
return val;
},
set() {console.warn("arcgisPackage 对象属性不能赋值");
},
}
);
export default arcgisPackage;
原作者👇👇👇
https://segmentfault.com/u/yo…
vue 组件调用
import arcgisPackage from "@/config/arcgisTools";
methods:{test(){let MapView = await arcgisPackage.MapView;}
}