2017-08-31 80 views

回答

0

只是使用加載事件。 e.g:

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

相關問題