小程序设置图片高度自适应

uniapp项目不支持img标签,只能用image标签,用image标签浏览器就会在外面解析出一层uni-image包在img外面,这样就会影响写样式,导致图片高度不能自适应,所以就拿原有图片的宽高,用rpx单位

javascript 复制代码
<template>
	
	<!-- 图片 -->
	<view style="height: 100%;width: 100%;" v-if="dataListconfiguration.scheduleType == 2">
		<image :style="{
            width: width,
            height: height,
          }" class="img" :src="dataListconfiguration.scheduleContent" ></image>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dataListconfiguration:uni.getStorageSync('dataListconfiguration'),
				width: "",
				height: "",
			}
		},
		onShow() {
			// 设置标题
			wx.setNavigationBarTitle({
			  title: this.$t('schedule.index'),
			})
			// 设置图片高度
			let that = this
			if(this.dataListconfiguration&&this.dataListconfiguration.scheduleType == 2){
				uni.getImageInfo({
				  src: this.dataListconfiguration.scheduleContent,
				  success: (image) => {
				    that.width = image.width + "rpx";
				    that.height = image.height + "rpx";
				  },
				});
			}
		}
	}
</script>

<style scoped lang="scss">

.img{
	max-width: 100%;
}
</style>
相关推荐
靠谱品牌推荐官4 分钟前
【高并发实战】如何基于缓存穿透治理机制设计一套高可用的小程序本地缓存中台架构?
缓存·小程序·架构
小羊Yveesss9 分钟前
商家小程序外卖订单打印方案:云打印机对接、分单逻辑与模板配置实战
小程序·apache
爱学习 爱分享19 小时前
微信小程序html 在 webview 会打开再缩放一下
微信小程序·小程序·html
梦梦代码精20 小时前
深度拆解:上门按摩系统如何成为本地生活“到家时代”的新引擎?
docker·小程序·uni-app·开源·生活·开源软件
Geek_Vison1 天前
如何借助小程序容器技术实现跨端APP的敏捷开发
小程序·apache·敏捷流程
xshirleyl1 天前
微信小程序开发week6-慕尚花坊项目
微信小程序·小程序
usdoc文档预览1 天前
国产化踩坑:Vue3 / React / 小程序如何免插件实现 OFD 及复杂 Office 文档同屏预览
前端·javascript·react.js·小程序·pdf·word·office文件在线预览
倒流时光三十年1 天前
第二章 小程序目录结构与核心文件详解
spring boot·小程序
维双云1 天前
从零到一:一份关于“做小程序的步骤”的完整实操指南
小程序
打瞌睡的朱尤2 天前
微信小程序126~160
微信小程序·小程序