If the script you're importing is a JS module, i.e., it has variables and/or functions exported using the export
declaration, then, in your component, you can use the await
operator along with the import
declaration (MDN) like so:
const importedModule = await import("http://xxx.xxx/XX.js")
(Remember to call the above declaration inside an async
function)
And then you can use it like so:
importedModule.sort()
If you see an error that says something like Error: Cannot find module
in the console, change your declaration to be like so:
const importedModule = await import(/* webpackIgnore: true */ "http://xxx.xxx/XX.js")
(On why the /* webpackIgnore: true */
comment is required, read this very-well-written answer)
If you import the external module like this, you won't need to add the <script>
tag in your html.