webpack - bootstrap-table 的安装无法与 rails 6、webpack 和 bootstrap5 一起正常工作,而是在 table 上设置 bootstra4 版本
问题描述
我做了什么
我有一个项目,其中 bootstrap5 工作正常。我试图安装引导表
yarn add bootstrap-table
在application.js
我得到:
import 'bootstrap-table/dist/bootstrap-table.min.js'
import 'bootstrap-table/dist/locale/bootstrap-table-de-DE.min.js'
在 backend.sass 中:
@import '~bootstrap-table/dist/bootstrap-table.min.css'
细节
jquery 添加了纱线,是 v3.6.0,我有第一个
import $ from 'jquery'
在application.js
并在environment.js
:
const { environment } = require('@rails/webpacker')
const coffee = require('./loaders/coffee')
const webpack = require('webpack')
environment.plugins.prepend('Provide', new webpack.ProvidePlugin({
$: 'jquery/src/jquery',
jQuery: 'jquery/src/jquery',
jquery: 'jquery',
'window.jQuery': 'jquery',
Popper: ['popper.js', 'default']
}))
问题
所以现在样式没有正确应用,它将 bootstrap4 应用于表类:
当我输入 bootstrap5 而不是正确应用样式时,否则不会。分页下拉菜单也不起作用。当我点击它时,什么都没有弹出。bootstrap5 的正常下拉菜单在 bootstrap-table 之外单独工作。
我试过的
我尝试了很多更改导入,安装了不同的纱线包。我在 github repo 上发现了这个问题。添加常量application.js
对我不起作用。
他们写的 bootstrap 版本同样会被读出index.js
:
let bootstrapVersion = 4
try {
const rawVersion = $.fn.dropdown.Constructor.VERSION
// Only try to parse VERSION if it is defined.
// It is undefined in older versions of Bootstrap (tested with 3.1.1).
if (rawVersion !== undefined) {
bootstrapVersion = parseInt(rawVersion, 10)
}
出于某种原因$.fn.dropdown.Constructor
对我来说是未定义的。尝试更改导入以解决此问题,但不确定为什么它不起作用。
解决方案
检查此处提供的答案https://github.com/wenzhixin/bootstrap-table/issues/5837#issuecomment-952301379
通过以下方式帮助解决了该问题:
// bootstrap.js
import 'bootstrap/dist/js/bootstrap'
window.bootstrap = {
Tooltip: {
VERSION: "5"
}
}
而是在导入 Bootstrap 表之前导入新的 bootstrap.jsapplication.js
例如:
import '../assets/js/bootstrap'
import 'bootstrap-table/dist/bootstrap-table.js'
import 'bootstrap-table/dist/bootstrap-table.min.css'
该文件可能必须包含在内,因为如果您尝试在其中添加,webpacker 可能会在导入后更改代码window.bootstrap ...
执行application.js
推荐阅读
- git - Git 偏移 PowerShell 中的文本
- vb.net - 从 Sharepoint 下载空白和 0KB 的文件
- amazon-web-services - 我如何在 aws _route_table 中做动态路由?
- php - 如何根据 Laravel 中的选定选项在 mysql 数据库的文本框中显示数据
- c++ - 运算符重载:用二进制“-”减法没有找到采用 _____ 类型的全局运算符(或没有可接受的转换)
- python - Python 重力模拟
- python - 如何将随机二进制信息添加到当前的“坐标”中?(Python)
- mysql - 如何获取MySQL表中列值相同的所有行?
- html - google fonts - 字体系列在页面后加载,如何解决?
- c++ - 指向具有指针成员的对象的指针数组的析构函数