在phoenix项目中,我可以使用以下命令在css文件中引用摘要img:
background-image: url("/images/phoenix.png");并且引用了:
http://localhost:4000/images/phoenix-5bd99a0d17dd41bc9d9bf6840abcc089.png?vsn=d我想引用相同的文件,但使用javascript添加的图像src如下:
document.querySelector('#my-img').src = '/images/phoenix.png';但这只是参考:
http://localhost:4000/images/phoenix.png如何将phoenix端点配置为提供已摘要的img文件?
(我希望此功能用于更新缓存文件)
发布于 2018-04-04 04:37:06
由于您事先知道图像文件,因此可以使用javascript变量并将该值设置为该图像文件的URL,然后在脚本中使用它
在您的.eex模板中类似于以下内容:
<script>
// using static_path(@conn, "/path/to/asset") will give the digested file url
var disgestedImageUrl ="<%= static_path(@conn, "/images/phoenix.png") %>";
</script>然后让脚本使用.js文件中的URL
<script>
document.querySelector('#my-img').src = digesterImageUrl;
</script>https://stackoverflow.com/questions/49406666
复制相似问题