如何在 webpack 中使用 select2? [英] How can I using select2 with webpack?
本文介绍了如何在 webpack 中使用 select2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 webpack 来管理我的所有资产,当我使用此代码要求 select2 (https://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
:
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();
});
这篇关于如何在 webpack 中使用 select2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文