admin管理员组文章数量:1404927
I'm trying to add jQuery in my project although i get an error that it is not defined
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' }, <-- gives me error
{ 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 is this happening, I'm obviously declaring jQuery before bootstrap-select.
I'm trying to add jQuery in my project although i get an error that it is not defined
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' }, <-- gives me error
{ 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 is this happening, I'm obviously declaring jQuery before bootstrap-select.
Share Improve this question edited Mar 28, 2022 at 7:13 kissu 47k16 gold badges90 silver badges189 bronze badges asked Jul 16, 2021 at 18:38 SteveSteve 6452 gold badges10 silver badges22 bronze badges 1- Prefer using NPM, to better handle the versioning of your package. Less error prone too. – kissu Commented Jul 16, 2021 at 19:07
1 Answer
Reset to default 6I do not remend adding jQuery to a Nuxt project.
But if you really want to, you can follow those steps:
- install it with
yarn add jquery
- add those to your
nuxt.config.js
file
import webpack from 'webpack'
export default {
// ...
build: {
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery'
})
]
},
}
- be sure that you do have the following in your
.eslintrc.js
file
module.exports = {
// ...
env: {
// ...
monjs: true,
jquery: true
},
}
Then, you can use it like this in a method
or alike
$("h2").addClass("tasty-class")
本文标签: javascriptHow to install jQuery into NuxtjsStack Overflow
版权声明:本文标题:javascript - How to install jQuery into Nuxt.js? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744870413a2629595.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论