Reputation: 304
having vue 3 npm app. I need to use jquery. So I npm installed jquery packaged. Now if I need to use it I just do:
import $ from "jquery";
This works but I have to do it in every single file! Isnt there a way to import jquery just in the most parent script (ie main.js or App.vue) and not to importi it in every single file like that? I use jquery in every file.
Upvotes: 0
Views: 40
Reputation: 3317
Add this in main.js
to allow access it from anywhere using this.$
import Vue from "vue";
import App from "./App.vue";
import jQuery from "jquery";
Vue.prototype.$= jQuery;
new Vue({
render: (h) => h(App)
}).$mount("#app");
Upvotes: 1
Reputation: 536
I have added this code into my main.js
import jQuery from "jquery";
window.jQuery = window.$ = jQuery;
Not sure that it is the best solution for me everything is working fine.
Upvotes: 0