注册
登录
Weex
如何在加载网络图像后动态更改图像视图高度,而不是修复图像高度?
返回
如何在加载网络图像后动态更改图像视图高度,而不是修复图像高度?
作者:
google你他吗
发布时间:
2025-03-12 07:36:11 (1天前)
转自:
<p> <br/> &LT; DIV&GT;<br/> &lt; image style =“width:280px; height:280px; margin-left:250px; margin-top:100px”:src =“picPath”&gt;&lt; / image&gt;<br/>&LT; / DIV&GT;<br/>在上面的foo.vue中,它指定了图像的宽度和高度,…<br/> <br/></p>
收藏
举报
2 条回复
0#
回复此人
v-star*위위
|
2019-08-31 10-32
<div class =“post-text”itemprop =“text”> <P> 只需使用load事件。例如: </p> <P> </p> <div class =“snippet”data-lang =“js”data-hide =“false”data-console =“true”data-babel =“false”> <div class =“snippet-code”> <pre class="snippet-code-html lang-html prettyprint-override"> <code> <template> <div style="width: 750px; background-color: #f4f4f4; margin-top: 10px;" v-for="(item, index) in storyJson"> <image v-if="item.type === 'image'" :src="item.value" style="width: 750px; height: 468px; margin-bottom: 10px;" @load="load" resize="contain"></image> </div> </template> <script> module.exports = { props: { storyJson: { default: function () { return []; } } }, methods: { setUpStoryJson(json) { this.storyJson = JSON.parse(json); }, load(e) { const naturalSize = e.size; const showHeight = naturalSize.naturalHeight * 750 / naturalSize.naturalWidth; e.target.setStyle('height', showHeight + 'px'); } } };</script> </code> </pre> </DIV> </DIV> <P> </p> </DIV>
编辑
登录
后才能参与评论