How to load external js file in my component VUE 2 (webpack)?

I already looked and I did not find. I have a url from an external js file and I’m importing in my index.html. The file is loading when the application starts.

however, the user will not use the features frequently; And I would like to upload this file only when a specific component was called.

I’m using the vue cli (vue 2) with template webpack.

And they do not working.

need to upload this file to use a payment gateway. can anybody help me?

I’ve tried something like:

import * as PagSeguroDirectPayment from 'https://stc.sandbox.pagseguro.uol.com.br/pagseguro/api/v2/checkout/pagseguro.directpayment.js';

required('https://stc.sandbox.pagseguro.uol.com.br/pagseguro/api/v2/checkout/pagseguro.directpayment.js');

You can’t import files from URLs.

Either you save them locally in your project, or you inlcude them with a script tag in your index.html file, and tell webpack that that this is an external resource. See docs here:

https://webpack.js.org/configuration/externals/

1 Like