[英]jQuery File Upload plugin with webpack $(...).fileupload is not a function
I am using Rails 6, and I need to use jquery file upload plugin, I would like to add manually instead of using yarn, so I downloaded this file here: https://cdnjs.cloudflare.com/ajax/libs/blueimp-file-upload/9.31.0/js/jquery.fileupload.js and put it into app/javascript
folder我使用的是 Rails 6,我需要使用 jquery 文件上传插件,我想手动添加而不是使用纱线,所以我在这里下载了这个文件: https : //cdnjs.cloudflare.com/ajax/libs/blueimp- file-upload/9.31.0/js/jquery.fileupload.js并将其放入
app/javascript
文件夹
then in app/javascript/packs/application.js
I added the line然后在
app/javascript/packs/application.js
我添加了这一行
require("jquery.fileupload")
In my app/javascript/main.js
:在我的
app/javascript/main.js
:
$('#file-input').fileupload()
I get the error :我收到错误:
TypeError: $(...).fileupload is not a function
If I put $('#file-input').fileupload()
in javascript/packs/application.js
like this :如果我像这样将
$('#file-input').fileupload()
放在javascript/packs/application.js
:
require("jquery.fileupload")
$('#file-input').fileupload()
The error disappear !错误消失! so the issue seems to be that the plugin can only be accessed in application.js and not in other files, how I can solve that ?
所以问题似乎是该插件只能在 application.js 中访问,而不能在其他文件中访问,我该如何解决?
I lost 2 or 3 hours trying use webpack without success.我失去了 2 或 3 个小时尝试使用 webpack 没有成功。
Then simple download *.js
files directly from blueimp repository to app/javascript/packs/vendor
and import it in application.js
.然后简单地将
*.js
文件直接从 blueimp 存储库下载到app/javascript/packs/vendor
并将其导入application.js
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.