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

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_915106321 小时前
HTTP 协议详解,HTTP 协议在真实运行环境中的表现差异
网络·网络协议·http·ios·小程序·uni-app·iphone
焦糖玛奇朵婷2 小时前
扭蛋机小程序:线上扭蛋机模式发展新形势[特殊字符]
大数据·数据库·程序人生·小程序·软件需求
云云只是个程序马喽3 小时前
海外短剧系统开发核心功能设计及上线材料准备
小程序·php
2501_916007473 小时前
iOS与Android符号还原服务统一重构实践总结
android·ios·小程序·重构·uni-app·iphone·webview
全栈软件开发4 小时前
最新壁纸头像小程序系统源码 带流量主
小程序
00后程序员张6 小时前
fastlane 结合 appuploader 命令行实现跨平台上传发布 iOS App
android·ios·小程序·https·uni-app·iphone·webview
2501_915106326 小时前
iOS 性能优化这件事,结合多工具分析运行期性能问题
android·ios·性能优化·小程序·uni-app·cocoa·iphone
鲁Q同志6 小时前
微信小程序调用上一页的方法(主包,分包)
微信小程序·小程序
风月歌6 小时前
小程序项目之基于微信小程序的高校课堂教学管理系统源代码(源码+文档)
java·微信小程序·小程序·毕业设计·源码
嘿siri6 小时前
自定义app端、小程序端和H5等多端自定义键盘输入框,跟随系统键盘弹出和隐藏
javascript·小程序·uni-app·uniapp