Webpack Encore &jQuery 插件:$(...).isotope 不是函数

编程入门 行业动态 更新时间:2024-10-14 02:24:25
本文介绍了Webpack Encore &jQuery 插件:$(...).isotope 不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在使用 Yarn & 进行 Symfony5 项目jQuery.当我尝试使用 jQuery 插件isotope-layout"时出现错误;使用 Webpack Encore.

I'm working on a Symfony5 project, with Yarn & jQuery. I have an error when I try to use the jQuery plugin "isotope-layout" with Webpack Encore.

我尝试修复它好几个小时,但我可能没有以正确的方式去做.

I try to fix it for many hours but I might not be doing it the right way.

这是我的代码:

webpack.config.js

// Same error with or without "autoProvidejQuery"
Encore.autoProvidejQuery();

app.js

import 'jquery';
import 'popper.js';
import 'bootstrap';
import 'isotope-layout';

// start the Stimulus application
import './bootstrap';

custom.js

import jQuery from 'jquery';
import 'isotope-layout';

(function ($) {

    // Here is the error :
    $(...).isotope({...});

})(jQuery);

错误:

Uncaught TypeError: $(...).isotope is not a function

推荐答案

在使用 Isotope 时,您不必使用 jQuery.您可以使用 他们的 Webpack 文档 中的此示例:

You don't have to use jQuery when using Isotope. You can use this example from their Webpack documentation:

var Isotope = require('isotope-layout');

var iso = new Isotope( '.grid', {
  // options...
});

如果你想使用 jQuery,还有一个例子.安装:

There is also an example if you want to use jQuery. To install it:

npm install jquery
npm install jquery-bridget

然后:

var $ = require('jquery');
var jQueryBridget = require('jquery-bridget');
var Isotope = require('isotope-layout');
// make Isotope a jQuery plugin
jQueryBridget( 'isotope', Isotope, $ );
// now you can use $().isotope()
$('.grid').isotope({
  // options...
});

如果您使用的是现代 Javascript(并且您使用的是 Webpack,太棒了!),您可能不需要 jQuery 在很多情况下.

If you're using modern Javascript (and you're using Webpack, great!), you might not need jQuery in many cases.

这篇关于Webpack Encore &jQuery 插件:$(...).isotope 不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-23 19:24:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1047418.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   插件   Encore   Webpack   amp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!