image - 无法从本地路径加载Nativescript vue中的图片,但是用http/https就可以了,为什么?
问题描述
我目前正在开发一个小的 Nativescript vue 项目,我对这项技术很陌生。我正在尝试从本地路径加载图像。当 src 是和 http 链接时,一切都很好,但是资产文件夹中的本地图像没有任何作用。我正在运行 Nativescript 6.0.2 和 Vue 3.9.3。我按照 Nativescript vue 网站上的指南启动项目。
我尝试了不同的东西。
<Image src="../assets/images/NativeScript-Vue.png" stretch="none" col="2" row="0"/>
不工作
<Image src="~/assets/images/NativeScript-Vue.png" stretch="none" col="2" row="0"/>
不工作
<Image src="https://www.google.com/images/errors/logo_sm_2.png" stretch="none" col="2" row="0"/>
确实有效
<Image :src="native_img" stretch="none" col="2" row="0"/>
data() {
return {
native_img: "~/assets/images/NativeScript_logo.png"
};
不工作
<Image :src="native_img" stretch="none" col="2" row="0"/>
data() {
return {
native_img: "https://play.nativescript.org/dist/assets/img/NativeScript_logo.png"
};
}
确实有效
而我的项目文件夹结构是 V2 项目结构 https://nativescript-vue.org/en/docs/getting-started/upgrade-guide/
感谢您的时间 ;)
解决方案
如果您的文件的位置是这样的:
- app
- App_Resources
- assets
- images
然后你应该像这样访问你的图像:
<Image src="~/assets/images/imageName.png" stretch="none"></Image>
推荐阅读
- checkbox - 在 Confluence 标记中成为复选框的 ASCII 字符
- mysql - Athena SQL 从可变数量的表创建表
- python - 负算法运行时间
- go - 将通用映射转换为 YAML。语言
- fortran - fortran案例中的文本输入?
- node.js - 如何在同一服务器上为静态目录和 Angular 客户端添加路由?
- java - Java&JDA - 在没有任何事件的情况下发送消息
- react-native - React Native E2E w/Detox 错误:“无法在设备上运行应用程序”
- prolog - 如何为“姐妹”关系建模,使其暗示性别
- c - 与内联配对时,使用快速 u32 访问读取对齐的内存可能会导致严格的别名问题