laravel loads it like
try {
window.$ = window.jQuery = require('jquery');
} catch (e) {}
and just attaches it to the global window object.
Hi, what is the best way to import jQuery from NPM with Laravel. I'm not using jQuery anywhere else other then in one component. I tried to to
import $ from 'jquery';
in the component but that didn't work. Any ideas how to get it to work? Because I'm trying to use
$.getJson
in my VueComponent but I only get this error
$.getJson is not a function
You should just need
window.$ = window.jQuery = require('jquery')
$ and jQuery are now global. Just use them in your Vue code.
let data = $('#something');
// let data = jQuery('#something');
If "its not working," show how you're using jquery inside Vue.
If you can go to your browsers console and just type $ and enter, and it shows a function instead of an error, then jquery is loaded and it's your use of it in Vue that is not correct.
Please or to participate in this conversation.