Within my Vue project, I have the need to fetch a script from a server location (e.g. https://myurl.com/API.js
).
This script contains a variable that I intend to utilize within my Vue component/view.
The issue arises when I attempt to load this script using the loadScript module:
import Vue from 'vue'
import LoadScript from 'vue-plugin-load-script';
Vue.use(LoadScript);
Vue.loadScript('https://quvia.cz:4443/portalAPI.js')
The script ends up loading after the Vue component, leading to situations where trying to
console.log(externalScriptVariable)
results in an undefined value. As a quick workaround, using setTimeout for 1 second allows the variable to be output successfully.
Is there any way in Vue.js to effectively "await" the script loading process, ensuring it loads before all other Vue components?