uni-app applet loading image optimization

Scenario: Larger images load very slowly, and there will be a long white screen, which makes the user experience poor.

 

Solution : Once you enter the page, before the picture is loaded successfully, perform loading...; the @load event will be triggered after the picture is loaded;

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

Guess you like

Origin blog.csdn.net/qq_38517231/article/details/130492227