如何从Sails.js中的视图访问资产/图像? [英] how to access assets/images from the view in Sails.js?

查看:82
本文介绍了如何从Sails.js中的视图访问资产/图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想在Sails-Project的视图中添加图像

I simply want to add an image in a view in my Sails-Project

我的视图文件具有位置

views/album/albums.ejs

并且图片位于

assets/images/placeholder.png

如果我添加这样的图像

<img src="../../assets/images/placeholder.png">

我收到此错误

GET    http://localhost:1337/assets/images/placeholder.png    404 (Not Found)

我错过了什么吗?

推荐答案

风帆使用Grunt(项目根目录中的Gruntfile.js)来在起帆过程中执行一些任务。其中一项任务是将文件从资产目录复制到.tmp / public /目录(在开发版本中)。因此,如果您将文件添加到资产目录,则需要重新启动帆(起帆),才能从.tmp / public /(公共可访问目录根目录)进行访问。同样重要的是要注意,如果您将文件直接放置到.tmp / public /,则可以立即访问,但是在下一帆时,它将被删除,因为Grunt任务之一是在复制新文件之前清除该目录。您可以在Sails文档中找到所有这些信息(资产资产管理),然后从项目根目录中读取Gruntfile.js

Sails use Grunt (Gruntfile.js in root of project) to execute some tasks during sails lift. One of that tasks is to copy files from assets directory to .tmp/public/ directory (in development version). So if u add your file to assets directory you will need to restart sails (sails lift) to get it accessible from .tmp/public/ (what is public accessible directory root). Also its important to note that if u put files directly to .tmp/public/ it will be accessible instant, but on next sails lift it will be deleted, since one of Grunt tasks is to clear that directory before copy new files. All of this u can find on sails documentation (assets and asset-management) and by reading Gruntfile.js in root of your project

这篇关于如何从Sails.js中的视图访问资产/图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆