2017-08-31 3 views
0
<div> 
    <image style="width: 280px;height: 280px;margin-left:250px;margin-top:100px" :src="picPath"></image> 
</div> 

上記のfoo.vueでは、イメージの幅と高さを指定していましたが、imageviewにイメージを読み込んだ後にイメージの幅と高さを変更する必要がある場合があります。私の質問は、そのために、foo.vueからネイティブのアンドロイド/イオスに何をすべきですか?前もって感謝します。ネットワーク画像を読み込んだ後に画像の高さを動的に変更する方法はありますか?

答えて

0

loadイベントを使用するだけです。例えば:

<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>

関連する問題