uni-app image标签 404错误之后替换为默认图片

<template>  
    <view v-for="(item, index) in Items" :key="index">  
        <image :src="item.imgUrl" mode="aspectFill" @error="error(index)"></image>  
    </view>  
</template>  

<script>  
    export default {  
        data() {  
            return {  
                Items: []//请求返回的数据  
            }  
        },  
        methods: {  
            error: function(index) {  //加载图片出现404错误之后用默认图片替换
                this.Items[index]['imgUrl'] = '../../static/logo.png'; //默认图片路径  
            }  
        }  
    }  
</script>

 

posted @ 2021-09-07 11:38  熊大大001(前端开发)  阅读(586)  评论(0)    收藏  举报