3

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.

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');

And they do not working.

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

asked Nov 12, 2017 at 3:23

2 Answers 2

1

Instead of using it in index.html, create a separate js file and copy the script from the link. Export the required method in js file and import it in the component required.

answered Jan 8, 2019 at 6:40
Sign up to request clarification or add additional context in comments.

Comments

0

This is one of those features that vue has that makes believe that it is really well thought out. To do such a thing is actually super easy.

I'm using this in my routes like this:

// home gets loaded always
const Home = import('@/pages/home')
// profile and account gets loaded on demand
const Profile = () => import('@/pages/profile')
const Account = () => import('@/pages/account')

When used with webpack, this will generate individual files for each component. (01.js, 02.js, etc) These files will load as needed.

answered Nov 12, 2017 at 5:17

3 Comments

also, forgot to mention. There is a talk that goes into it further that's worth listening to at youtu.be/rn97hCNQsKI
My question is not how to loading file internal lazily. I need to know how to load an external file. stc.sandbox.pagseguro.uol.com.br/pagseguro/api/v2/checkout/….
is there a reason why externals don't work for this? webpack.js.org/configuration/externals/#externals

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.