Vue introduction how to introduce external script?

how to introduce external script into Vue?

I have a piece of the following code. I want to introduce it into the vue project. How can I introduce it?

< script src= " https://www.abcx.com/api/chec.;></script>

our components are:

<style>
...
</style>

<template>
...
</template>

<script>
...
</script>

where can I introduce the script above?

Mar.05,2021

var elem = document.createElement("script");
elem.src = url;
document.body.appendChild(elem);
elem.onload = elem.onreadystatechange = function () {
    if (!this.readyState || this.readyState === "loaded" || this.readyState === "complete") {
        if (callback) {
           callback();
        }
    }
}

vue-cli scaffolding project? Introducing other components directly into index.html is accessible


can be directly introduced in index.html in your root directory < script src= "https://www.abcx.com/api/chec.;></script>, and the component can directly access your introduced dependency because it is loaded globally.
is like Baidu Map's dependence, which is directly introduced in index.html .


import xxx from 'xxx.js' ?


use scaffolding to directly import you


import 'https://www.abcx.com/api/chec...'

index.html to introduce


inport is not necessarily a good solution.
in fact, this kind of problem is best to see if npm has a corresponding library. If you write a third-party library, you'd better package it into es6's module or CommonmJs, so that you can inport and requier.
but if the modularity of the introduced third-party libraries is not good enough.
then it's better to use the tag directly in index.html
to see what format the module you want to use is in.

Menu