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

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>
相关推荐
恩创软件开发9 小时前
创业日常2026-1-8
java·经验分享·微信小程序·小程序
开发加微信:hedian11617 小时前
推客与分销场景下的系统架构实践:如何支撑高并发与复杂业务规则
小程序
游九尘19 小时前
在小程序中实现横竖屏切换的配置方法,实时监听页面宽度
小程序
weixin_lynhgworld19 小时前
[特殊字符]旧物焕新颜,二手变宝藏——小程序系统开发开启绿色生活新篇章[特殊字符]
小程序·生活
说私域19 小时前
小程序电商运营中“开源AI智能名片链动2+1模式S2B2C商城小程序”对培养“老铁”用户的重要性研究
人工智能·小程序·开源
00后程序员张19 小时前
在 iPhone 上进行 iOS 网络抓包的实践经验
android·ios·小程序·https·uni-app·iphone·webview
weixin_lynhgworld19 小时前
[特殊字符]短剧小程序:解锁碎片时间,畅享无限娱乐[特殊字符]
小程序·娱乐
2501_9159184119 小时前
介绍如何在电脑上查看 iPhone 和 iPad 的完整设备信息
android·ios·小程序·uni-app·电脑·iphone·ipad
2501_9160088919 小时前
没有 Mac 如何在 Windows 上创建 iOS 应用描述文件
android·macos·ios·小程序·uni-app·iphone·webview
菜鸟学习成功之路-李飞2 天前
免费开源一款作文批改小程序模版,下载即可二开
小程序·开源