Answer the question
In order to leave comments, you need to log in
How to import jQuery for all Vue components?
I am translating a project from js and jQUery to view.
I want jQUery to work for now. I will replace the functionality gradually.
I read that you can just import it into a component. And you can install via npm.
Actually, I installed it. At import in a component works.
But when importing in main.js and using it in new Veu, I don’t understand how to access it from the components.
//main.js:
import $ from 'jquery'
////
new Vue({
$,
router,
store,
axios,
VueAxios,
render: function (h) { return h(App) }
}).$mount('#app')
Answer the question
In order to leave comments, you need to log in
I think you will find a solution here https://coderoad.ru/53355086/%D0%94%D0%BE%D0%B1%D0... , as I understand it, you need to install ProvidePlugin and write in vue.config
const webpack = require('webpack')
module.exports = {
configureWebpack: {
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jquery: 'jquery',
'window.jQuery': 'jquery',
jQuery: 'jquery'
})
]
},
}
and then in main.js writewindow.$ = window.jQuery = require('jquery');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question