我有一个使用Chestnut创建的应用程序,并且在项目中的位置有一个图像: resources/public/img.png。我想在我的应用程序中使用此图像,但执行[:img {:src "public/img.png"}]或[:img {:src "./img.png"}]不起作用。资源文件夹中图像的正确src是什么?
发布于 2020-03-19 22:57:10
目录部分resources/public是隐式的。您需要像这样访问该文件:
(ns demo.core
(:require [clojure.java.io :as io]))
; something like this
(slurp (io/resource "img.png")) ; returns bytes from file
(io/stream (io/resource "img.png")) ; returns in InputStream for file例如:
(ns tst.demo.core
(:use tupelo.core tupelo.test)
(:require [clojure.java.io :as io]))
(dotest
(let [bytes (slurp (io/resource "sample.json"))]
(spyx (count bytes))))有结果
(count bytes) => 72发布于 2020-03-20 11:17:23
转到您的project.clj文件并搜索figwheel设置。确保:http-server-root是未注释的。
:figwheel {
:http-server-root "public" ;; serve static assets from resources/public/
...
}那么[:img {:src "img.png" }]应该可以工作了。别忘了重启figwheel。
发布于 2020-03-20 01:16:57
我没有用过栗子。我假设有一个dir服务器在运行,它的根目录是resources/public。我假设该文件夹中有一个index.html (或等效项)。我进一步假设您想要的卡顿位于该index.html文件中。考虑到以上所有情况,我会尝试
:img {:src "img.png"}
https://stackoverflow.com/questions/60758763
复制相似问题