I just used the CLI and installed F7 with Cordova and webpack. I have some plugins that need jQuery to work. My question is what is the best way to include jQuery?
What does it have to do with F7?
I’m new to doing things this way and thought I’d ask here as I followed the directions on F7. Is that good enough for you or do you want an in depth thesis on why I posted here?
First, install jquery:
npm i jquery
Then in the very top of your main JS file (app.js):
import jQuery from 'jquery'; window.jQuery = jQuery; window.$ = jQuery;
Thank you, you are always helpful!
Thank you really helpful.
I got this.
SyntaxError: import declarations may only appear at top level of a module.
If you don’t use webpack, then just include it in index.html via
<script src="..."> tag
This works, but how can i add third party jquery plugins to the app?
Same as JQuery - add them to the <script src=… after the JQuery
Yeah i did that, for example i want to load this plugin (payform)
I have loaded it in the index page
When i call it payform init in the component page it does not work. <script> ccnum = $('#card-number'); expiry = $('#expiration'); cvc = $('#cvc'); submit = document.getElementById('submit'); result = document.getElementById('result'); type = document.getElementById('ccnum-type'); payform.cardNumberInput(ccnum); payform.expiryInput(expiry); payform.cvcInput(cvc); // Format input for card number entry $('#card-number').payform('formatCardNumber'); // Validate a credit card number $.payform.validateCardNumber('4242 4242 4242 4242'); //=> true // Get card type from number $.payform.parseCardType('4242 4242 4242 4242'); //=> 'visa' </script>
but when i place this script inside the main index.html it returns an error.
Uncaught ReferenceError: payform is not defined
You’ve loaded JQuery version - shouldn’t you use $.payform ???
Then how do i initiate the jquery plugin in the component page?
You have so many page events - choose one.