I have to load some scripts in my vue3 component, so this is what i'm doing:
<script setup>
import { onMounted } from 'vue'
function createEl (el, url, type) {
const script = document.createElement(el)
if (type) script.type = type
script.src = url
return script
}
onMounted(() => {
const neshanScript = createEl('script', 'https://static.neshan.org/sdk/openlayers/5.3.0/ol.js', 'text/javascript')
neshanScript.onload = () => {
const map = new neshanScript.Map({
target: 'map',
maptype: 'neshan',
poi: true,
traffic: false
})
console.log(map)
}
neshanScript.onerror = () => console.log('error')
})
</script>
createEl function helps me to create any element I need, then I need to take an instance from my loaded script, but I onload block doesn't run!