天天看点

vant展示组件之Lazyload 懒加载

版本号:

vue/cli:4.5.12

vant:^3.0.10

使用方式:

// 在main.js文件中
import {
	createApp
} from 'vue'
import {
    Lazyload
} from 'vant'
import default from '@/assets/images/default.png'

// 注册
createApp(App).use(Lazyload, {
    lazyComponent: true,
    attempt: 3,
    loading: default,
    error: default,
});
           

相关问题:

1. 在van-swipe组件中使用时显示空白

<van-swipe :autoplay="3000" indicator-color="white" :width="300">
    <van-swipe-item v-for="(item,index) in oData" :key="index">
        <lazy-component>
			<img v-lazy="item.picUrl" />
		</lazy-component>
	</van-swipe-item>
</van-swipe>
           

 解决方式:

不需要使用lazy-component组件直接使用v-lazy即可

<van-swipe :autoplay="3000" indicator-color="white" :width="300">
    <van-swipe-item v-for="(item,index) in oData" :key="index">
        <img :v-lazy="item.picUrl" />
    </van-swipe-item>
</van-swipe>
           

继续阅读