# vue-viewload **Repository Path**: mirrors_singod/vue-viewload ## Basic Information - **Project Name**: vue-viewload - **Description**: vue图片懒加载lazyload,依赖vue2.0以上版本。支持图片或者其他资源进入可视区域后加载。 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-09-25 - **Last Updated**: 2026-03-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # vue-viewload    vue图片懒加载,依赖vue2.0以上版本。图片或者其他资源进入可视区域后加载。 # 支持浏览器  |  |  |  |  |  | --- | --- | --- | --- | --- | --- | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 11+ ✔ | # 例子预览 例子就是/demo目录下的文件 - [例子列表](https://shuizhubocai.github.io/vue-viewload/demo/index.html) - [纵向滚动的例子](https://shuizhubocai.github.io/vue-viewload/demo/html/app1.html) - [横向滚动的例子](https://shuizhubocai.github.io/vue-viewload/demo/html/app2.html) - [在容器内滚动的例子](https://shuizhubocai.github.io/vue-viewload/demo/html/app3.html) - [懒加载选项设置](https://shuizhubocai.github.io/vue-viewload/demo/html/app4.html) - [非img元素进入可视区域后单独执行回调函数(不依赖全局options选项回调函数),比如可以在回调函数中执行ajax请求](https://shuizhubocai.github.io/vue-viewload/demo/html/app5.html) # 扫码查看例子入口 [](https://shuizhubocai.github.io/vue-viewload/demo/index.html) # 安装vue-viewload 使用npm在本地安装: ```bash npm install vue-viewload --save-dev ``` # 使用vue-viewload js文件中 ```javascript //需要引入vue,以及vue-viewload,下面的axios是ajax库,如果不需要可以不引用 import Vue from 'vue' import VueViewload from 'vue-viewload' import axios from 'axios' //使用VueViewload Vue.use(VueViewload) new Vue({ el: '#app', data: { pic: 'http://pics.sc.chinaz.com/files/pic/pic9/201701/bpic232.jpg', list: [ 'http://pics.sc.chinaz.com/files/pic/pic9/201702/zzpic1399.jpg', 'http://pics.sc.chinaz.com/files/pic/pic9/201612/fpic9875.jpg', 'http://pics.sc.chinaz.com/files/pic/pic9/201610/fpic8220.jpg', 'http://pics.sc.chinaz.com/files/pic/pic9/201611/fpic8607.jpg', 'http://pics.sc.chinaz.com/files/pic/pic9/201611/fpic8745.jpg', 'http://pics.sc.chinaz.com/files/pic/pic9/201701/zzpic437.jpg', 'http://pics.sc.chinaz.com/files/pic/pic9/201610/apic23881.jpg', 'http://pics.sc.chinaz.com/files/pic/pic9/201608/fpic5949.jpg', 'http://pics.sc.chinaz.com/files/pic/pic9/201608/fpic6419.jpg', 'http://pics.sc.chinaz.com/files/pic/pic9/201609/fpic7403.jpg', 'http://pics.sc.chinaz.com/files/pic/pic9/201609/fpic7317.jpg', 'http://pics.sc.chinaz.com/files/pic/pic9/201605/fpic1376.jpg', 'http://pics.sc.chinaz.com/files/pic/pic9/201606/apic21195.jpg', 'http://pics.sc.chinaz.com/files/pic/pic9/201606/apic21465.jpg', 'http://pics.sc.chinaz.com/files/pic/pic9/201604/apic20040.jpg', 'http://pics.sc.chinaz.com/files/pic/pic9/201604/fpic914.jpg', 'http://pics.sc.chinaz.com/files/pic/pic9/201604/fpic873.jpg', 'http://pics.sc.chinaz.com/files/pic/pic9/201605/fpic1208.jpg' ] }, methods: { //函数需要返回一个函数 getAjaxContent: function() { return function() { axios({ method: 'get', url: '../api/data.txt' }).then((response) => { this.innerHTML = response.data; }) } } } }) ``` html文件中,在要进行懒加载的元素上添加vue指令v-view,值为加载资源的URL或methods方法。需要懒加载的元素请尽量设置宽高样式 ```html
