-
Notifications
You must be signed in to change notification settings - Fork 349
/
Copy pathApp.vue
147 lines (139 loc) · 3.76 KB
/
App.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<template lang="pug">
#app
a#header(href="https://github.com/lfyfly/vue-waterfall-easy",target="_blank",title="github of vue-waterfall-easy") vue-waterfall-easy
button(:style="{position:'fixed',zIndex:10000}", @click="changeImgArr") changeImgArr
a.typetype(href="https://dazidazi.com", target="_blank")
button(:style="{position:'fixed',zIndex:10000, left: '120px'}") 程序员提高打字速度
#content
//- vue-waterfall-easy(ref="waterfall",:imgsArr="imgsArr",@scrollReachBottom="getData", @click="clickFn", :enablePullDownEvent="true", @pullDownMove="pullDownMove",@pullDownEnd="pullDownEnd")
vue-waterfall-easy(ref="waterfall",:imgsArr="imgsArr",@scrollReachBottom="getData", @click="clickFn", @imgError="imgErrorFn")
.img-info(slot-scope="props")
p.some-info 第{{props.index+1}}张图片
p.some-info {{props.value.info}}
//-div(slot="waterfall-head")
h1 waterfall-head
h1 waterfall-head
//- 自定义加载动画
//-div(slot="loading" slot-scope="{isFirstLoad}")
div(slot="loading" v-if="isFirstLoad") first-loading...
div(v-else) loading...
</template>
<script>
import vueWaterfallEasy from './vue-waterfall-easy/vue-waterfall-easy.vue'
import axios from 'axios'
export default {
name: 'app',
data() {
return {
imgsArr: [],
group: 0, // 当前加载的加载图片的次数
pullDownDistance: 0
}
},
components: {
vueWaterfallEasy
},
methods: {
getData() {
axios.get('./static/mock/data.json?group=' + this.group) // 真实环境中,后端会根据参数group返回新的图片数组,这里我用一个静态json文件模拟
.then(res => {
this.group++
if (this.group === 10) { // 模拟已经无新数据,显示 slot="waterfall-over"
this.$refs.waterfall.waterfallOver()
return
}
this.imgsArr = this.imgsArr.concat(res.data)
})
},
clickFn(event, { index, value }) {
// event.preventDefault()
if (event.target.tagName.toLowerCase() == 'img') {
console.log('img clicked', index, value)
}
},
imgErrorFn(imgItem){
console.log('图片加载错误',imgItem)
},
changeImgArr() {
axios.get('./static/mock/data-change.json') // 真实环境中,后端会根据参数group返回新的图片数组,这里我用一个静态json文件模拟
.then(res => {
this.imgsArr = res.data
})
},
pullDownMove(pullDownDistance) {
// console.log('pullDownDistance', pullDownDistance)
this.pullDownDistance = pullDownDistance
},
pullDownEnd(pullDownDistance) {
console.log('pullDownEnd')
if(this.pullDownDistance>50){
alert('下拉刷新')
}
this.pullDownDistance = 0
},
},
created() {
this.getData()
// 删除某个卡片
// setTimeout(()=>{
// this.imgsArr.splice(1,1)
// },2000)
},
}
</script>
<style lang="scss">
* {
margin: 0;
padding: 0;
}
a {
color: #000;
text-decoration: none;
&:active {
color: #000;
}
}
html,
body,
#app {
height: 100%;
}
.typetype button{
cursor: pointer;
font-size: 18px;
padding: 0 10px;
}
#app {
position: relative;
#header {
display: block;
text-align: center;
background: #000;
color: #cccccc;
line-height: 32px;
font-size: 16px;
font-weight: bold;
letter-spacing: 2px;
position: fixed;
z-index: 999;
width: 100%;
}
#content {
position: absolute;
top: 32px;
bottom: 0;
width: 100%;
}
}
// .__err__ .img-wraper {
// background: url(/static/img/1.jpg) no-repeat center/100px 100px !important;
// }
#app {
overflow: auto;
position: relative;
.some-info {
line-height: 1.6;
text-align: center;
}
}
</style>