rails 如何在 webpacker 上使用 uppy 插件
How to use uppy plugin with webpacker on rails
我正在尝试在 rails 上将 uppy 与 webpacker 结合使用,但我无法让 uppy 工作:
// app/javascripts/src/javascript/my_scripts.js
const Uppy = require('@uppy/core')
const DragDrop = require('@uppy/drag-drop')
const ProgressBar = require('@uppy/progress-bar')
const uppyOne = new Uppy({debug: true, autoProceed: true})
uppyOne.use(DragDrop, { target: '.UppyDragDrop-One' })
这是我收到的控制台错误:
[Uppy] [23:29:46] Not installing DragDrop
Plugin.js:165 Uncaught Error: Invalid target option given to DragDrop. Please make sure that the element
exists on the page, or that the plugin you are targeting has been installed. Check that the <script> tag initializing Uppy
comes at the bottom of the page, before the closing </body> tag (see https://github.com/transloadit/uppy/issues/1042).
at DragDrop.mount (Plugin.js:165)
at DragDrop.install (index.js:204)
at Uppy.use (index.js:901)
at Object.<anonymous> (uppy.js:6)
at __webpack_require__ (bootstrap a698a4c3b9adcd1bf843:19)
at Object.<anonymous> (application.js:1)
at __webpack_require__ (bootstrap a698a4c3b9adcd1bf843:19)
at bootstrap a698a4c3b9adcd1bf843:62
at bootstrap a698a4c3b9adcd1bf843:62
我发现问题是因为在 rails 中,您通常 link 布局文件头部的所有 JS 文件,但带有 class '.UppyDragDrop' 的元素尚未渲染。
解决需要在出现DragDrog元素后通过javascript_pack_tag单独link到javascript
我正在尝试在 rails 上将 uppy 与 webpacker 结合使用,但我无法让 uppy 工作:
// app/javascripts/src/javascript/my_scripts.js
const Uppy = require('@uppy/core')
const DragDrop = require('@uppy/drag-drop')
const ProgressBar = require('@uppy/progress-bar')
const uppyOne = new Uppy({debug: true, autoProceed: true})
uppyOne.use(DragDrop, { target: '.UppyDragDrop-One' })
这是我收到的控制台错误:
[Uppy] [23:29:46] Not installing DragDrop
Plugin.js:165 Uncaught Error: Invalid target option given to DragDrop. Please make sure that the element
exists on the page, or that the plugin you are targeting has been installed. Check that the <script> tag initializing Uppy
comes at the bottom of the page, before the closing </body> tag (see https://github.com/transloadit/uppy/issues/1042).
at DragDrop.mount (Plugin.js:165)
at DragDrop.install (index.js:204)
at Uppy.use (index.js:901)
at Object.<anonymous> (uppy.js:6)
at __webpack_require__ (bootstrap a698a4c3b9adcd1bf843:19)
at Object.<anonymous> (application.js:1)
at __webpack_require__ (bootstrap a698a4c3b9adcd1bf843:19)
at bootstrap a698a4c3b9adcd1bf843:62
at bootstrap a698a4c3b9adcd1bf843:62
我发现问题是因为在 rails 中,您通常 link 布局文件头部的所有 JS 文件,但带有 class '.UppyDragDrop' 的元素尚未渲染。
解决需要在出现DragDrog元素后通过javascript_pack_tag单独link到javascript