如何将select2与webpack一起使用? [英] How can I using select2 with webpack?

查看:57
本文介绍了如何将select2与webpack一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用此代码要求select2( https://时,我正在使用webpack来管理我的所有资产. github.com/select2/select2 )我收到了错误

I'm using webpack to manage all my assets, when I use this code to require select2 (https://github.com/select2/select2) I got the error

$(...).select2不起作用.

$(...).select2 is not function.

require.ensure(['./vendors/select2'],function (require) {
    require('./site');
});

// site.js
(function ($) {
    $(document).ready(function () {
        $(".js-1example-basic-single").select2();
    });
})(jQuery);

我认为模块导出有问题. 我尝试了很多搜索,但没有希望.

I think there is something wrong with module export. I tried many search but no hope.

任何人都请告诉我该怎么办,这花了我大约10个小时.

Anyone please tell me what to do, It took me about 10 hours.

谢谢!

推荐答案

您可以通过以下方式运行select2:

You can run select2 in this way:

import $ from 'jquery';
import 'select2';                       // globally assign select2 fn to $ element
import 'select2/dist/css/select2.css';  // optional if you have css loader

$(() => {
  $('.select2-enable').select2();
});

这篇关于如何将select2与webpack一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆