当前位置: 代码迷 >> 综合 >> vue 图片懒加载,走到哪显示哪的图片
  详细解决方案

vue 图片懒加载,走到哪显示哪的图片

热度:0   发布时间:2024-02-20 04:51:20.0
下载依赖:
npm install --save-dev vue-view-lazy

 main.js引入:


import vView from 'vue-view-lazy'
Vue.use(vView,{error:'../../static/images/loading.png',loading:'../../static/images/loading.gif',
});

html:

 

<template><ul id='img'><li class="in" v-for="(item,i) in imgs" :key="i"><img src="#" alt="图片" v-view-lazy="item.src"></li></ul>
</template><script>export default {data () {return {imgs:[{src:'../../static/images/img1.jpg'},{src:'../../static/images/img2.png'},{src:'../../static/images/img2.jpg'},{src:'../../static/images/img3.jpg'},{src:'../../static/images/img4.jpg'},{src:'../../static/images/img5.jpeg'},  ]}},mounted(){},}
</script>
<style scoped>...
</style>

 

  相关解决方案