Comments (4)
Thanks for your response -- that's very helpful and far more elegant than prefixing every call with window. .
"Unless I've misunderstood something, I don't see this as an issue with this
library or it's documentation, but rather your understanding of scope and
linters."
Well, think of it this way. Your library is incredibly useful, as it enables coders to do things they previously were unable to do. That means many of us have never been in a position to need that level of familiarity with linters or scoping rules. Globals are deliberately avoided in many tutorials on Vue for reasons of design philosophy. I discovered this module was via a suggestion on StackOverflow, and one comment in response to it (that went unanswered) was "How to call a function from the loaded script?" so I'm not the only one who got confused.
Adding a brief note in the instructions for the aid of such people will make your library easier for people to use.
Here's my suggestion, based on what you've just told me, continuing your example of the Google Maps API, and using an example from Google's API docs:
Once imported, javascript libraries can be accessed by their usual name, eg
this.map = new google.maps.Map(document.getElementById("map") as HTMLElement, {
center: { lat: -34.397, lng: 150.644 },
zoom: 8,
});
However, if you are using a linter to check your code, this may report as an undefined variable. You will need to instruct your linter to ignore this variable or function. Instructions for ESlint here
If you are unable to resolve this in your linter, adding window.
before the name of the variable or function you are attempting to access will also correct this problem, e.g.:
this.map = new window.google.maps.Map(document.getElementById("map") as HTMLElement, {
center: { lat: -34.397, lng: 150.644 },
zoom: 8,
});
So no, there's nothing wrong with your instructions, and again thanks for making this incredibly useful library available. I'm just suggesting a small usability improvement.
from vue-plugin-load-script.
And obviously the answer is that I just need to qualify the scope as window.JitsiMeetExternalAPI and everything works fine.
I think it's worth including a note in the instructions to that effect:
To access a function from the loaded script, you may need to prefix the function name with window. to access the full browser scope and ensure compatibility across devices.
from vue-plugin-load-script.
Well, I must say it also took me a while to understand what to do with this plugin, I event uninstalled it because it basically does nothing. Until I understood it loads the scripts in the global scope. So maybe a line or two about that fact wouldn't hurt, linter or not, scope understanding or not
from vue-plugin-load-script.
from vue-plugin-load-script.
Related Issues (20)
- Race Condition HOT 4
- npm and yarn install HOT 2
- Load multiple scripts simultaneously HOT 3
- No Ts support HOT 6
- Getting error: Uncaught ReferenceError: undefinedLoadScript is not defined
- [Object Object] HOT 1
- What about CompositionAPI import? HOT 3
- [Feature Request] Add style support
- Can't import when using Nuxt HOT 2
- Installation error with Vue 3 - Cannot set property "$loadScript" of undefined HOT 5
- VUE SSR Issue HOT 3
- Adding defer and async options HOT 1
- Type definition in v1.3.4 overrides local Vue type definitions HOT 3
- Object(...) is not a function HOT 3
- Typescript 4.5.4 errors with Vue.install HOT 2
- 2022 - Plugin no longer works at all, this should be archived HOT 1
- how to load a vue compiled app into current app HOT 2
- v1.3.2 typescript definition not compatible with Vue 2.6
- error when running ssr + mix
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue-plugin-load-script.