问题描述
需要图片按照比例缩放,
问题出现的环境背景及自己尝试过哪些方法
我有试过在@load函数内进行操作,但是效果不理想
相关代码
// 请把代码文本粘贴到下方(请勿用图片代替代码)
<template>
<image :src="val.primary_pic_url" :ref="'limg'+i" @load="leftimg(i,$event)" class='img' ></template>
</html>
<script>
leftimg(i,event){
var that=this;
const view = that.$refs['limg'+i];
if(view[0].ref == event.target.ref){
if(WXEnvironment.platform != 'Web'){
// that.msg=view;
// this.msg1=event;
// 365px
var rqwidth=365;
var width=event.size.naturalWidth,height=event.size.naturalHeight;
var ratio = rqwidth/width;
// that.msg=ratio;
width = ratio*width;
height = ratio*height;
this.testh=height;
this.testw=width;
animation.transition(view,{
styles:{
width: width+'px',
height: height+'px'
},
duration: 0,
timingFunction: 'ease',
delay: 0,
needLayout:true
}, function(){})
}
}
},
</script>
leftimg(i,event){