├── .gitignore ├── examples ├── dist │ ├── app.0614ed0d.js.gz │ ├── app.87e188a3.css │ └── app.0614ed0d.js ├── index.js ├── tpl.html └── app.vue ├── commitlint.config.js ├── postcss.config.js ├── .babelrc ├── test ├── utils.js ├── webpack.test.config.js ├── list.spec.js └── karma.conf.js ├── .travis.yml ├── src ├── index.js ├── list.less ├── debounce.js └── lazy-list.js ├── config └── index.js ├── index.html ├── .eslintrc ├── LICENSE ├── webpack.build.config.js ├── README.md ├── package.json └── dist └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | coverage 3 | package-lock.json 4 | .cache 5 | .DS_Store -------------------------------------------------------------------------------- /examples/dist/app.0614ed0d.js.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dwqs/v2-lazy-list/HEAD/examples/dist/app.0614ed0d.js.gz -------------------------------------------------------------------------------- /commitlint.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['@commitlint/config-angular'], 3 | rules: { 4 | 'subject-case': [0] 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: [ 3 | require('autoprefixer')({ browsers: ['last 5 versions', 'Android >= 4.0', 'iOS >= 9'] }) 4 | ] 5 | }; 6 | -------------------------------------------------------------------------------- /examples/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | 3 | import 'beautify-scrollbar/dist/index.css'; 4 | import V2LazyList from '../src/index'; 5 | 6 | import App from './app'; 7 | 8 | Vue.use(V2LazyList); 9 | 10 | new Vue({ 11 | el: '#app', 12 | render: (h) => h(App) 13 | }); 14 | -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | [ 4 | "env", { 5 | "targets": { 6 | "browsers": ["last 5 versions", "safari > 8"] 7 | }, 8 | "modules": false, 9 | "loose": true 10 | } 11 | ], 12 | "stage-2" 13 | ] 14 | } -------------------------------------------------------------------------------- /test/utils.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | import V2LazyList from 'main/index'; 3 | 4 | Vue.use(V2LazyList); 5 | 6 | export const createVM = (opts) => { 7 | return new Vue(opts).$mount(); 8 | }; 9 | 10 | export const destroyVM = (vm) => { 11 | vm.$destroy && vm.$destroy(); 12 | vm.$el && 13 | vm.$el.parentNode && 14 | vm.$el.parentNode.removeChild(vm.$el); 15 | }; 16 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | sudo: false 3 | dist: trusty 4 | install: 5 | - npm install 6 | cache: 7 | directories: 8 | - node_modules 9 | addons: 10 | chrome: stable 11 | before_install: 12 | - export CHROME_BIN=chromium-browser 13 | - export DISPLAY=:99.0 14 | - sh -e /etc/init.d/xvfb start 15 | branches: 16 | only: 17 | - master 18 | node_js: 19 | - '8' 20 | script: 21 | - npm test -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import './list.less'; 2 | import LazyList from './lazy-list.js'; 3 | 4 | function install (Vue) { 5 | if (Vue.version < 2.5) { 6 | throw new Error('Only adapted to Vue 2.5.0 or higher'); 7 | } 8 | Vue.component(LazyList.name, LazyList); 9 | } 10 | 11 | const V2LazyList = { 12 | install 13 | }; 14 | 15 | export default V2LazyList; 16 | 17 | if (typeof window !== 'undefined' && window.Vue) { 18 | window.Vue.use(V2LazyList); 19 | }; 20 | -------------------------------------------------------------------------------- /config/index.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | 3 | module.exports = { 4 | dev: { 5 | env: 'development', 6 | assetsRoot: path.resolve(__dirname, '../examples/dist'), 7 | assetsPublicPath: '/v2-lazy-list/examples/dist/', 8 | contentBase: path.resolve(__dirname, '../examples/dist'), 9 | port: 3001 10 | }, 11 | build: { 12 | env: 'production', 13 | assetsRoot: path.resolve(__dirname, '../examples/dist'), 14 | assetsPublicPath: '/v2-lazy-list/examples/dist/' 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 |
npm i --save v2-lazy-list beautify-scrollbar12 |
Or
13 |yarn add v2-lazy-list beautify-scrollbar14 |
import Vue from 'vue';18 |
import 'beautify-scrollbar/dist/index.css';
import V2LazyList from 'v2-lazy-list';
Vue.use(V2LazyList);
<v2-lazy-list :data='data'></v2-lazy-list>22 |
45 | <v2-lazy-list :data='list' :height="500" :item-height="40"
46 | tag="div"
47 | item-tag="div"
48 | >
49 | <template slot-scope="item">
50 | <span>\{\{item\}\}</span>
51 | </template>
52 | </v2-lazy-list>
53 |
54 |
75 | <v2-lazy-list :data='list' :height="500" :item-height="40"
76 | tag="div"
77 | item-tag="div"
78 | mode="lazy"
79 | >
80 | <template slot-scope="item">
81 | <span>\{\{item\}\}</span>
82 | </template>
83 | </v2-lazy-list>
84 |
85 | 95 | <v2-lazy-list :data='list2' height="500" item-height="40" 96 | :threshold="20" 97 | @reach-threshold="appendList2Data" 98 | > 99 | </v2-lazy-list> 100 |101 |