uni-app小程序加载图片优化

场景:较大的图片加载很慢,会出现较长时间的白屏,体验感差。

 

解决方案:一进入页面,图片未加载成功前,进行loading…;图片加载完成后会触发@load事件;

<template>
  <view class="">
    <image @load="loadImg($event)"  src="../static/image.jpg" mode="widthFix" />
  </view>
</template>

<script>
export default {
  data () {
    return {
      
    }
  },
  onShow () {
    //开启加载
    uni.showLoading({
      title: '加载中...',
      mask: true
    })
  },
  methods: {
    // 此方法会在图片加载完成后触发
    loadImg (e) {
      uni.hideLoading()
      console.log('图片信息', e)
    },
  },
}
</script>

<style>
</style>

猜你喜欢

转载自blog.csdn.net/qq_38517231/article/details/130492227