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

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>
相关推荐
2501_916007474 分钟前
iOS 26 软件性能测试 新版系统下评估全流程 + 多工具辅助方案
android·macos·ios·小程序·uni-app·cocoa·iphone
00后程序员张1 小时前
Swoole HTTPS 实战,在生产环境部署、性能权衡与排查流程
后端·ios·小程序·https·uni-app·iphone·swoole
從南走到北1 小时前
智尚房产中介小程序
微信小程序·小程序
2501_915909064 小时前
iOS App 上架全流程详解:证书配置、打包上传、审核技巧与跨平台上架工具 开心上架 实践
android·ios·小程序·https·uni-app·iphone·webview
2501_915106324 小时前
iOS 26 系统流畅度测试实战分享,多工具组合辅助策略
android·macos·ios·小程序·uni-app·cocoa·iphone
2501_915918414 小时前
开发 iOS 应用全流程指南,环境搭建、证书配置与跨平台使用 开心上架 上架AppStore
android·ios·小程序·https·uni-app·iphone·webview
從南走到北5 小时前
房屋出租出售预约系统
微信小程序·小程序
2501_9159214313 小时前
iOS 是开源的吗?苹果系统的封闭与开放边界全解析(含开发与开心上架(Appuploader)实战)
android·ios·小程序·uni-app·开源·iphone·webview
2501_9159090616 小时前
原生 iOS 开发全流程实战,Swift 技术栈、工程结构、自动化上传与上架发布指南
android·ios·小程序·uni-app·自动化·iphone·swift