我正尝试在我的新ClojureScript和Reagent应用程序中使用react-beautiful-dnd。根据博客here,它说我需要在我的project.clj文件中包含使用:foreign-libs的文件。
我已经进行了如下配置
:cljsbuild
{:builds {:min
{:source-paths ["src/cljs" "src/cljc" "env/prod/cljs"]
:compiler
{:output-to "target/cljsbuild/public/js/app.js"
:output-dir "target/cljsbuild/public/js"
:source-map "target/cljsbuild/public/js/app.js.map"
:optimizations :advanced
:foreign-libs [{:file "src/cljs/react-beautiful-dnd/react-beautiful-dnd.js"}]
:pretty-print false}}
:app
{:source-paths ["src/cljs" "src/cljc" "env/dev/cljs"]
:figwheel {:on-jsload "toka.core/mount-root"}
:compiler
{:main "toka.dev"
:asset-path "/js/out"
:output-to "target/cljsbuild/public/js/app.js"
:output-dir "target/cljsbuild/public/js/out"
:source-map true
:optimizations :none
:pretty-print true}}
}
}我从here获得了编译后的文件,并将其复制到我的项目中。尽管经过所有这些更改,我仍然不能在我的组件中使用DragDropContext或Droppable。
我在我的组件中声明了它们,如下所示
(def DragDropContext (reagent/adapt-react-class js/DragDropContext))
(def Droppable (reagent/adapt-react-class js/Droppable))有没有人能帮我弄明白我到底做错了什么?我收到如下错误
Uncaught ReferenceError: DragDropContext is not defined
at core.cljs?rel=1508832729388:11
(anonymous) @ core.cljs?rel=1508832729388:11注意:我没有在foreign-libs中添加任何provide属性,因为我不确定包。另外,我不确定是否需要在core.cljs组件文件中执行一些:require操作。
发布于 2018-02-28 04:40:33
我也在努力解决同样的问题,并找到了解决方案。组件被放在一个单独的名称空间中,因此必须像这样引用:
(def DragDropContext (reagent/adapt-react-class js/ReactBeautifulDnd.DragDropContext))
(def Droppable (reagent/adapt-react-class js/ReactBeautifulDnd.Draggable))发布于 2017-10-24 17:12:21
你需要添加:provides (你可以选择任何想要的ns名称,例如react-beautiful-dnd),然后require它,这样它就被加载了。因为它依赖于React,所以您应该在requires中指定它(例如,如果您包含React作为cljsjs.react依赖项,则将其指定为CLJSJS ):
[{:file "src/cljs/react-beautiful-dnd/react-beautiful-dnd.js"
:provides ["react-beautiful-dnd"]
:requires ["cljsjs.react"]}]在您的命名空间中:
(ns my.ns
(:require
[cljsjs.react]
[react-beautiful-dnd]))https://stackoverflow.com/questions/46905604
复制相似问题