【问题标题】:Images in public directory of Meteor JS are not loadingMeteor JS公共目录中的图像未加载
【发布时间】:2017-09-26 16:45:37
【问题描述】:

我遵循了一个建议创建一个公共目录来保存图像、字体和 js 文件的文档。它读取字体,但不显示图像,但是当我手动导航到它显示的浏览器上的图像时,会出现什么问题?目录结构:

app_root->public->assets->img->1.jpg

在浏览器上:http://localhost:3000/assets/img/portfolio/1.jpg 显示图像。我有什么错?

【问题讨论】:

  • 你的图片标签是什么样的?这种错误通常是由于使用相对路径而不是绝对路径造成的。
  • 确保 /public 不在您的 img 路径中 - /public 被映射到 /

标签: javascript image meteor directory static-files


【解决方案1】:

不要使用绝对链接,使用相对链接! Meteor 构建 css、scss、js、图像文件。文件结构:

/
/public
/public/img/
/public/img/1.jpg

试试这个:

<img src="/img/1.jpg" alt="First image">

如果你想从外部访问它,你必须在路由器中设置它。

上一个答案:How to serve static content (images, fonts etc.) using iron router

服务器静态示例:https://gist.github.com/goje87/8aa5c04bf3b0f5de907d

【讨论】:

    猜你喜欢
    • 2021-01-17
    • 1970-01-01
    • 2015-03-30
    • 1970-01-01
    • 1970-01-01
    • 2014-02-02
    • 1970-01-01
    • 2020-04-11
    • 1970-01-01
    相关资源
    最近更新 更多