1***@qq.com
1***@qq.com
  • 发布:2019-05-30 20:28
  • 更新:2020-02-27 03:05
  • 阅读:6143

uniapp的image标签 src404之后,怎么设置默认图片啊

分类:uni-app

试了@error,但是this的上下文并不是img标签的。

2019-05-30 20:28 负责人:无 分享
已邀请:
笑笑吧

笑笑吧


    export default {    
        data() {    
            return {    
                audioList: [],    
                    audioPlaySrc: 0,    
            }    
        },    
        methods {    
            test(HandleEvent) {    

                this.audioList[this.audioPlaySrc]='../../static/image/default.png';      

            },    
        }    
    }  
  • 1***@qq.com (作者)

    这个方法可行,谢谢啦。

    2019-05-31 13:51

  • x***@qq.com

    回复 1***@qq.com: 这样写。真机测试为什么不显示呢?H5有默认图片。

    2019-10-22 11:48

1***@qq.com

1***@qq.com (作者)

<image class="zhuan" :src="audioList[audioPlaySrc].img" @error="test(e)"></image>  

    export default {  
        data() {  
            return {  
                audioList: [],  
                    audioPlaySrc: 0,  
            }  
        },  
        methods {  
            test(HandleEvent) {  
                console.log(this); //打印出来是vue对象    
                console.log(HandleEvent); //打印出来是undefined    
                //怎么实现下面的代码?    
                // this.src='../../static/image/default.png';    
                // this.onerror=null;    
            },  
        }  
    }
笑笑吧

笑笑吧

很简单,做个判断就可以了。

<image class="zhuan" :src="audioList[audioPlaySrc].img||'默认图片路径'" >

  • 1***@qq.com (作者)

    audioList[audioPlaySrc].img是网络地址,不会为空,但是地址可能请求不到图片。

    2019-05-31 09:58

the_wolf_life

the_wolf_life - 大前端领航者

可以参考这个试试
<image :src="item.image"
class="[item.loaded]" mode="aspectFill"
lazy-load
@load="onImageLoad('cartList', index)"
@error="onImageError('cartList', index)"
></image>

//监听image加载完成
onImageLoad(key, index) {
this.$set(this[key][index], 'loaded', 'loaded');
},
//监听image加载失败
onImageError(key, index) {
this[key][index].image = '/static/errorImage.jpg';
},

1***@qq.com

1***@qq.com

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

<script>  
    export default {  
        data() {  
            return {  
                Items: []//请求的数据  
            }  
        },  
        methods: {  
            error: function(index) {  
                this.Items[index]['img'] = '../../static/logo.png';//默认图片  
            }  
        }  
    }  
</script>

该问题目前已经被锁定, 无法添加新回复