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

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_915909066 小时前
WebView 调试工具全解析,解决“看不见的移动端问题”
android·ios·小程序·https·uni-app·iphone·webview
说私域7 小时前
“开源链动2+1模式AI智能名片S2B2C商城小程序”在拉群营销中的应用与效果
人工智能·小程序
2501_915106328 小时前
App 怎么上架 iOS?从准备资料到开心上架(Appuploader)免 Mac 上传的完整实战流程指南
android·macos·ios·小程序·uni-app·iphone·webview
环信即时通讯云10 小时前
实现小程序 uniApp 输入框展示自定义表情包
小程序·uni-app
2501_9159214313 小时前
iOS 抓不到包怎么办?工程化排查与替代抓包方案(抓包/HTTPS/Charles代理/tcpdump)
android·ios·小程序·https·uni-app·iphone·tcpdump
JSON_L14 小时前
Fastadmin中使用小程序登录
小程序·php·fastadmin
星光一影15 小时前
悬赏任务平台/拉新地推系统源码
redis·mysql·小程序·php·uniapp·html5
2501_9159184116 小时前
Fiddler抓包工具详解,HTTP/HTTPS抓包、代理设置与调试技巧一站式教程(含实战案例)
http·ios·小程序·https·fiddler·uni-app·webview
一匹电信狗16 小时前
【C++】哈希表详解(开放定址法+哈希桶)
服务器·c++·leetcode·小程序·stl·哈希算法·散列表
2501_9159090619 小时前
iOS 发布 App 全流程指南,从签名打包到开心上架(Appuploader)跨平台免 Mac 上传实战
android·macos·ios·小程序·uni-app·cocoa·iphone