当前位置: 首页 > news >正文

uni-app:多种方法写入图片路径

一、文件在前端文件夹中

1、相对路径引用

从当前文件所在位置开始寻找图片文件的路径。../../ 表示返回两级目录,即从当前文件所在的 wind.vue 所在的位置开始向上回退两级。接着,进入 static 目录,再进入 look 目录,最后定位到 wind.png 图片文件。

wind: '../../static/look/wind.png', //相对路径引用

<template><view><image :src="wind" mode=""></image></view>
</template>
<script>export default {data() {return {wind: '../../static/look/wind.png', //相对路径引用}; },methods: {}};
</script>
<style>image {width:300rpx;height:300rpx;}
</style>

2、绝对路径引用

@别名的绝对路径,表示从项目根目录开始寻找图片文件的路径。在Vue CLI 3及以上版本中,@默认指向src/目录。

wind:require('@/static/look/wind.png'),//绝对路径引用

<template><view><image :src="wind" mode=""></image></view>
</template>
<script>export default {data() {return {wind:require('@/static/look/wind.png'),//绝对路径引用}; },methods: {}};
</script>
<style>image {width:300rpx;height:300rpx;}
</style>

二、文件在后端文件夹中

在宝塔中我的图片路径大概是这样的/www/wwwroot/XXXX/public/icon/look/wind.png

  

wind:'http://XXXX/icon/look/wind.png',//XXXX表示你的服务器端域名

<template><view><image :src="wind" mode=""></image></view>
</template>
<script>export default {data() {return {wind:'http://XXXX/icon/look/wind.png',}; },methods: {}};
</script>
<style>image {width:300rpx;height:300rpx;}
</style>

http://www.lryc.cn/news/203992.html

相关文章:

  • 共谋工业3D视觉发展,深眸科技以自研解决方案拓宽场景应用边界
  • 前端面试基础面试题——11
  • SQL server中内连接和外连接的区别、表达(表的连接)
  • Linux中的shell外壳与权限(包含目录文件的权限,粘滞位的来龙去脉)
  • 力扣第45题 跳跃游戏II c++ 贪心算法
  • 1024动态
  • 中心胖AP(AD9430DN)+远端管理单元RU(R240D)+出口网关,实现组网
  • shell_45.Linux在脚本中使用 getopt
  • 2023-8-20 CVTE视源股份后端开发实习一面
  • 二叉树进阶
  • 前端性能优化 - 虚拟滚动
  • 手写 Promise(1)核心功能的实现
  • 深入探究Java内存模型
  • 深度学习 | Pytorch深度学习实践 (Chapter 10、11 CNN)
  • 谈谈你对spring boot 3.0的理解
  • 【大数据】Hadoop
  • Spring实例化源码解析之Bean的实例化(十二)
  • git常用的几条命令介绍
  • 使用VisualSVN在Windows系统上设置SVN服务器,并结合内网穿透实现公网访问
  • 第18章 SpringCloud生态(三)
  • leetcode:2347. 最好的扑克手牌(python3解法)
  • 2007-2022 年上市公司国内外专利授权情况数据
  • 安全渗透测试网络基础知识之路由技术
  • 【大数据】Kafka 实战教程(二)
  • React 框架
  • 数据结构与算法之图: Leetcode 133. 克隆图 (Typescript版)
  • illuminate/database 使用 一
  • 前端koa搭建服务器(保姆级教程)——part1
  • js逆向第一课 密码学介绍
  • Dynamic DataSource 多数据源配置【 Springboot + DataSource + MyBatis Plus + Druid】