Playing a bit with Framework7 svelte and confused about how to import jQuery into the project (or even Dom 7). I’ve added jQuery to my node_modules and tried adding jQuery in App.js with
import * as $j from 'jquery';
(since $ is reserved in svelte) but no luck. Any help on doing this as well as the best place to put additional jQuery code would be greatly appreciated.
import jQuery from ‘jquery’;
import dom7 from ‘dom7’;
In App.js, before
import Framework7 from 'framework7/framework7-lite.esm.bundle.js';
?
Also,what file would be the best place to add my jQuery code snippets? Just trying to set it up in the most efficient way. Thanks
After a bit of experimentation, this works well.
import { onMount } from 'svelte';
import js from 'jquery';
onMount(() => {
window.js = js; //could use anything here: window.jQuery = jQuery;
});
One question is, if I have jQuery code I wish to use in a Framework7 svelte project, where is the best location for it to be located? I’m not sure what the best file location should be or if it should be in a separate .js file. Any suggestions would be appreciated.
This question is not really correct/relevant, JS modules is not the same as <script src>
. Check how they work and how to use them https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
In JS modules, we usually import libraries/scripts/utils in every file where we need to reference theme and don’t use global variables like window.js = js
, that is the main point of JS modules