[英]Select 2 Webpack-encore
I'm trying to use select2 with webpack-encore on my symphony4 project.我正在尝试在我的 symphony4 项目中使用 select2 和 webpack-encore。 My app.js file is loaded without problem but not select2 while i installed it.. I do not understand why it's not working at all...我的 app.js 文件加载没有问题,但在我安装它时没有 select2.. 我不明白为什么它根本不工作......
My html我的 html
<head>
{{ encore_entry_link_tags('app') }}
{{ encore_entry_script_tags('app') }}
</head>
<body>
<select>
<option value="">--Please choose an option--</option>
<option value="dog">Dog</option>
<option value="cat">Cat</option>
<option value="hamster">Hamster</option>
</select>
My app.js我的 app.js
require('../css/app.css');
const $ = require('jquery');
console.log('Hello Webpackfdsfds Encore! Edit me in assets/js/app.js');
require('select2')
$('select').select2({ width: '100%', placeholder: "Select an Option", allowClear: true })
What it looks like https://imgur.com/Wh1zMn8它看起来像什么https://imgur.com/Wh1zMn8
I would be grateful if you would help me如果你能帮助我,我将不胜感激
You can simply import the select2 CSS with a require:您可以简单地导入 select2 CSS并需要:
require('../css/app.css');
const $ = require('jquery');
console.log('Hello Webpackfdsfds Encore! Edit me in assets/js/app.js');
require('select2')
require('select2/dist/css/select2.css')
$('select').select2({ width: '100%', placeholder: "Select an Option", allowClear: true })
It also exists custom styles, like:它还存在自定义 styles,如:
You can install them with yarn.您可以使用纱线安装它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.