I'm facing an issue with adding external JavaScript (using CDN) and accessing its methods.
I attempted to add it in the mounted hook, but I'm not confident if this is the best approach:
mounted() {
let leafMap = document.createElement("script");
leafMap.setAttribute(
"src",
"https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="93fff6f2f5fff6e7d3a2bda4bda2">[email protected]</a>/dist/leaflet.js"
);
document.head.appendChild(leafMap);
}
I can access it from Vue methods using:
window.L //window.<packageName>
However, when the page is created, window.L
is undefined. So, I need to wait for the script to load. What would be the best way to manage this process?