javascript - 使用 webpack 获取 'Uncaught TypeError: $(...).tablesorter is not a function'
问题描述
Uncaught TypeError: $(...).tablesorter is not a function
在使用 Webpack 迁移到 Rails 6 后,我得到了。这是我的 environment.js
const { environment } = require('@rails/webpacker')
const webpack = require('webpack')
environment.plugins.prepend('Provide',
new webpack.ProvidePlugin({
$: 'jquery/src/jquery',
jQuery: 'jquery/src/jquery',
tablesorter: 'tablesorter',
bootstrap: 'bootstrap/dist/js/bootstrap',
draggable: 'plain-draggable'
})
)
module.exports = environment
相关的其他插件工作正常。
解决方案
我不知道究竟是为什么,但它的工作原理是这样的:
import $ from 'jquery'
import 'tablesorter'
$(document).on('turbolinks:load', () => {
$('.tablesorter').tablesorter()
})
推荐阅读
- python - Python any() 和 zip() 内置函数解释?
- python-3.x - 浮点值的 Pandas Dataframe 减法产生与预期不同的值
- javascript - 如何在反应中将两个不同的数据推送到数组中
- apache-flink - Apache Flink 中的窗口和状态
- reactjs - 是否有一种有效的方法可以根据当前通过 uid 登录的用户返回数据?
- flutter - 我如何在颤动中获取文档ID
- xml - IMPORT XML 函数 - 股票价格 - Google 表格
- javascript - JavaScript Every() 方法返回假,即使它是真的?
- linux - 更改 Dockerfile 中的某些内容时,如何阻止 docker 从头开始下载所有内容?
- java - 如何使用 PDFViewer 在 Android 的 Webview 中打开 pdf