简体   繁体   English

如何在Webpacker上使用Uppy插件

[英]How to use uppy plugin with webpacker on rails

I'm trying to use uppy with webpacker on rails, I am having trouble getting uppy to work: 我正在尝试将uppy与webpacker一起使用,但无法正常工作:

//  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' })

This is the console error I'm receiving: 这是我收到的控制台错误:

[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

I found out the problem is because in rails you usually link to all JS files up in the head of the layout file but the element with class '.UppyDragDrop' has yet to be rendered. 我发现问题是因为在rails中,您通常链接到布局文件开头的所有JS文件,但是类'.UppyDragDrop'的元素尚未呈现。

To resolve, you need to separately link to the javascript via javascript_pack_tag after the element with the DragDrog element is presented. 要解决此问题,您需要在显示具有DragDrog元素的元素之后通过javascript_pack_tag单独链接到javascript。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM