Although I tried adding jQuery to my project, I encountered an error saying it was undefined.
plugins: [ { src: '~/plugins/js/svgSprite.js', mode: 'client' }, { src: '~/plugins/vendor/jquery/jquery.min.js', mode: 'client' }, { src: '~/plugins/vendor/bootstrap/js/bootstrap.bundle.min.js', mode: 'client' }, { src: '~/plugins/vendor/bootstrap-select/js/bootstrap-select.min.js', mode: 'client' }, <-- 给我报错 { src: '~/plugins/vendor/magnific-popup/jquery.magnific-popup.min.js', mode: 'client' }, { src: '~/plugins/vendor/smooth-scroll/smooth-scroll.polyfills.min.js', mode: 'client' }, { src: '~/plugins/vendor/object-fit-images/ofi.min.js', mode: 'client' }, { src: '~/plugins/js/theme.js', mode: 'client' } ],
Why this happens, obviously I have declared jQuery before bootstrap-select.
I do not recommend adding jQuery to Nuxt projects.
But if youreallywant to add it, you can follow the steps below:
yarn add jquery
Install itnuxt.config.js
file.eslintrc.js
file has the following contentThen, you can use it like this in
method
or similar