Skip to content

Commit b0184f1

Browse files
committed
build demo
1 parent 982523f commit b0184f1

File tree

9 files changed

+175
-40
lines changed

9 files changed

+175
-40
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
node_modules/
33
npm-debug*
44
.idea/
5+
onlineDemo/

README.md

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ $ npm install vue-scroll-list --save-dev
1515
```
1616

1717
## Demos
18-
on the road...
18+
19+
[infinite data](http://freeui.org/vue-scroll-list/)
1920

2021
## Usage
2122

2223
```html
2324
<template>
2425
<div id="app">
26+
<h2>vue-scroll-list with infinite data</h2>
27+
<h3>random height</h3>
28+
<h4>total: {{count}}</h4>
2529
<ul>
2630
<scroll-list
2731
:heights="heightList"
@@ -30,9 +34,9 @@ on the road...
3034
@toBottom="onBottom"
3135
@scrolling="onScroll">
3236
<li v-for="(item, index) in list"
33-
:key="item.name"
34-
:style="{height: item.itemHeight + 'px'}">
35-
{{item.name}}/{{item.price}}/{{item.itemHeight}}
37+
:key="item.index"
38+
:style="{height: item.itemHeight + 'px', 'line-height': item.itemHeight + 'px'}">
39+
index:{{item.index}} / height:{{item.itemHeight}}
3640
</li>
3741
</scroll-list>
3842
</ul>
@@ -55,38 +59,55 @@ on the road...
5559
},
5660
methods: {
5761
onTop() {
58-
console.log('page to top.');
62+
console.log('[demo]:page to top.');
5963
},
6064
onBottom() {
61-
console.log('page to bottom.');
62-
this.createData();
65+
console.log('[demo]:page to bottom.');
66+
!window.__stopLoadData && this.createData();
6367
},
6468
onScroll(event) {
65-
console.log(event);
69+
window.__showScrollEvent && console.log(event);
6670
},
6771
createData() {
68-
let size = 40;
72+
let size = window.__createSize || 40;
6973
this.count += size;
7074
for (let i = this.count - size; i < this.count; i++) {
71-
let itemHeight = Math.random() > 0.5 ? 40 : 100;
75+
let itemHeight = Math.round(Math.random() * 100) + 40;
7276
this.list.push({
73-
name: 'name-' + i,
74-
price: Math.floor(Math.random() * 1000),
77+
index: i,
7578
itemHeight: itemHeight
7679
});
7780
this.heightList.push(itemHeight);
7881
}
82+
console.log('[demo]:' + size + ' items are created.')
7983
}
8084
},
8185
created() {
86+
window.__createSize = 40;
87+
window.__stopLoadData = false;
88+
window.__showScrollEvent = false;
8289
this.createData();
8390
}
8491
};
8592
</script>
8693
<style scoped>
94+
#app {
95+
text-align: center;
96+
}
97+
8798
ul {
88-
border: 1px solid #eee;
8999
height: 400px;
100+
padding: 0;
101+
border: 1px solid #eee;
102+
}
103+
104+
li {
105+
border-bottom: 1px solid #eee;
106+
overflow: hidden;
107+
}
108+
109+
li:last-child {
110+
border-bottom: 0;
90111
}
91112
92113
.scroll-container {

dist/vue-scroll-list.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ var component = {
5353
var delta = this.$options.delta;
5454
var overs = this.findOvers(offset);
5555

56+
// scroll to top
5657
if (!offset && delta.total) {
5758
this.$emit('toTop');
5859
}
@@ -63,7 +64,7 @@ var component = {
6364
return a + b;
6465
});
6566

66-
// console.log(offset, this.$el.clientHeight, totalHeight);
67+
// scroll to bottom
6768
if (offset && offset + this.$el.clientHeight >= totalHeight) {
6869
start = delta.total - delta.keeps;
6970
end = delta.total - 1;

example/App.vue

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<template>
22
<div id="app">
3+
<h2>vue-scroll-list with infinite data</h2>
4+
<h3>random height</h3>
5+
<h4>total: {{count}}</h4>
36
<ul>
47
<scroll-list
58
:heights="heightList"
@@ -8,9 +11,9 @@
811
@toBottom="onBottom"
912
@scrolling="onScroll">
1013
<li v-for="(item, index) in list"
11-
:key="item.name"
12-
:style="{height: item.itemHeight + 'px'}">
13-
{{item.name}}/{{item.price}}/{{item.itemHeight}}
14+
:key="item.index"
15+
:style="{height: item.itemHeight + 'px', 'line-height': item.itemHeight + 'px'}">
16+
index:{{item.index}} / height:{{item.itemHeight}}
1417
</li>
1518
</scroll-list>
1619
</ul>
@@ -33,38 +36,62 @@
3336
},
3437
methods: {
3538
onTop() {
36-
console.log('page to top.');
39+
console.log('[demo]:page to top.');
3740
},
3841
onBottom() {
39-
console.log('page to bottom.');
40-
this.createData();
42+
console.log('[demo]:page to bottom.');
43+
!window.__stopLoadData && this.createData();
4144
},
4245
onScroll(event) {
43-
console.log(event);
46+
window.__showScrollEvent && console.log(event);
4447
},
4548
createData() {
46-
let size = 40;
49+
let size = window.__createSize || 40;
4750
this.count += size;
4851
for (let i = this.count - size; i < this.count; i++) {
49-
let itemHeight = Math.random() > 0.5 ? 40 : 100;
52+
let itemHeight = Math.round(Math.random() * 100) + 40;
5053
this.list.push({
51-
name: 'name-' + i,
52-
price: Math.floor(Math.random() * 1000),
54+
index: i,
5355
itemHeight: itemHeight
5456
});
5557
this.heightList.push(itemHeight);
5658
}
59+
console.log('[demo]:' + size + ' items are created.')
60+
},
61+
logSomeInfo() {
62+
console.log('%cThere are some useful variables in window object:', 'color: green');
63+
console.log('%c- `__createSize`: the number of items are created every time.', 'color: green');
64+
console.log('%c- `__stopLoadData`: set true to stop loading data when the page is on bottom.', 'color: green');
65+
console.log('%c- `__showScrollEvent`: set true to show scroll event.', 'color: green');
5766
}
5867
},
5968
created() {
69+
window.__createSize = 40;
70+
window.__stopLoadData = false;
71+
window.__showScrollEvent = false;
6072
this.createData();
73+
this.logSomeInfo();
6174
}
6275
};
6376
</script>
6477
<style scoped>
78+
#app {
79+
text-align: center;
80+
}
81+
6582
ul {
66-
border: 1px solid #eee;
6783
height: 400px;
84+
padding: 0;
85+
border: 1px solid #eee;
86+
}
87+
88+
li {
89+
border-bottom: 1px solid #eee;
90+
overflow: hidden;
91+
}
92+
93+
li:last-child {
94+
border-bottom: 0;
6895
}
6996
7097
.scroll-container {

example/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8">
5-
<title>test&example</title>
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
6+
<title>vue-scroll-list</title>
67
</head>
78
<body>
89
<div id="app"></div>
9-
<script src="/build/index.js"></script>
1010
</body>
1111
</html>

package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
},
99
"scripts": {
1010
"dist": "rollup -c",
11-
"dev": "webpack-dev-server --config webpack.config.js --open --inline --hot"
11+
"buildDemo": "webpack --config webpack.config.demo.js",
12+
"dev": "webpack-dev-server --config webpack.config.dev.js --open --inline --hot"
1213
},
1314
"repository": {
1415
"type": "git",
@@ -26,9 +27,18 @@
2627
},
2728
"homepage": "https://github.com/KyLeoHC/vue-scroll-list#readme",
2829
"devDependencies": {
30+
"babel-core": "^6.25.0",
31+
"babel-loader": "^7.1.0",
2932
"babel-plugin-external-helpers": "^6.22.0",
33+
"babel-plugin-transform-runtime": "^6.23.0",
3034
"babel-preset-es2015": "^6.24.1",
35+
"babel-runtime": "^6.23.0",
3136
"css-loader": "^0.28.4",
37+
"css-select": "^1.3.0-rc0",
38+
"html-webpack-plugin": "^2.28.0",
39+
"htmlparser2": "^3.9.2",
40+
"pretty-error": "^2.1.1",
41+
"renderkid": "^2.0.1",
3242
"rollup": "^0.43.0",
3343
"rollup-plugin-babel": "^2.7.1",
3444
"vue": "^2.3.4",
Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ let config = {
55
entry: {
66
index: './example/index'
77
},
8-
output: {
9-
path: path.resolve(__dirname, 'build'),
10-
publicPath: '/build/',
11-
filename: '[name].js'
12-
},
138
resolve: {
149
extensions: ['.js', '.vue'],
1510
alias: {
@@ -23,15 +18,28 @@ let config = {
2318
test: /\.vue$/,
2419
loader: 'vue-loader',
2520
options: {}
21+
},
22+
{
23+
test: /\.js$/,
24+
exclude: /node_modules/,
25+
use: [
26+
{
27+
loader: 'babel-loader'
28+
}
29+
]
2630
}
2731
]
2832
},
29-
devServer: {
30-
contentBase: './example',
31-
host: '0.0.0.0',
32-
port: '8686',
33-
noInfo: true
34-
}
33+
plugins: [
34+
new webpack.LoaderOptionsPlugin({
35+
options: {
36+
babel: {
37+
presets: ['es2015'],
38+
plugins: ['transform-runtime']
39+
}
40+
}
41+
})
42+
]
3543
};
3644

3745
module.exports = config;

webpack.config.demo.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const path = require('path');
2+
const webpack = require('webpack');
3+
const baseConfig = require('./webpack.config.base');
4+
const HtmlWebpackPlugin = require('html-webpack-plugin');
5+
6+
baseConfig.output = {
7+
path: path.resolve(__dirname, 'onlineDemo'),
8+
publicPath: '/vue-scroll-list/',
9+
filename: '[name].[hash].js',
10+
sourceMapFilename: '[file].map'
11+
};
12+
13+
baseConfig.plugins.push(
14+
new webpack.DefinePlugin({
15+
'process.env': {
16+
NODE_ENV: '"production"'
17+
}
18+
})
19+
);
20+
21+
baseConfig.plugins.push(
22+
new webpack.optimize.UglifyJsPlugin({
23+
compress: {
24+
warnings: false
25+
},
26+
comments: false,
27+
sourceMap: true
28+
})
29+
);
30+
31+
baseConfig.plugins.push(
32+
new HtmlWebpackPlugin({
33+
title: 'vue-scroll-list',
34+
template: 'example/index.html',
35+
filename: 'index.html'
36+
})
37+
);
38+
39+
baseConfig.devtool = 'source-map';
40+
41+
module.exports = baseConfig;

webpack.config.dev.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const path = require('path');
2+
const webpack = require('webpack');
3+
const baseConfig = require('./webpack.config.base');
4+
const HtmlWebpackPlugin = require('html-webpack-plugin');
5+
6+
baseConfig.output = {
7+
path: path.resolve(__dirname, 'build'),
8+
publicPath: '/',
9+
filename: '[name].js'
10+
};
11+
12+
baseConfig.plugins.push(
13+
new HtmlWebpackPlugin({
14+
title: 'vue-scroll-list',
15+
template: 'example/index.html',
16+
filename: 'index.html'
17+
})
18+
);
19+
20+
baseConfig.devServer = {
21+
host: '0.0.0.0',
22+
port: '8686',
23+
noInfo: true
24+
};
25+
26+
module.exports = baseConfig;

0 commit comments

Comments
 (0)