-
Notifications
You must be signed in to change notification settings - Fork 0
/
three.vue
146 lines (132 loc) · 4.77 KB
/
three.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
<template>
<div class="three">
<scroll>
</scroll>
<div class="activity">
<div class="activity_content" ref="lists" >
<div class="box" v-for="(n,i) in lists " :key="i"> {{n.title}}</div>
<div style="text-align: center; width: 100%;height: 50px;margin: auto;background:#fff;line-height: 50px;" v-if="isShow">
<img src="../assets/image/loading.gif" alt="" width="100"></div>
<div v-else style="text-align: center; width: 100%;height: 50px;">-- 到底了哦 --</div>
</div>
</div>
</div>
</template>
<script>
import scroll from '../components/scroll'
export default {
name: "three",
components: {scroll},
created() {
this.$store.commit('set_current', 1);
this.getInfo();
},
data() {
return {
lists: [],
page: 1,
isTrue: false,
isShow: false,
}
},
methods: {
getInfo() {
this.$http({
method: "post",
url: "http://192.168.0.97/changlu/home/information/informationList?size=4",
dataType: "json",
data: {
cid: 1,
p: this.page
},
})
.then(res => {
if (res.data.status == 1) {
console.log(res)
this.lists = this.lists.concat(res.data.result.param);
if (res.data.result.param.length < 4) {
this.isTrue = false;
this.isShow = false;
} else {
this.isTrue = true;
this.isShow = true;
}
}
})
.catch(err => {
console.log(err);
})
},
/* getHeight() {
this.$http({
method: "post",
url: "http://192.168.0.98/changlu/home/information/informationList?size=4",
dataType: "json",
data: {
cid: 1,
p:this.page
},
})
.then(res => {
if (res.data.status == 1) {
this.lists=this.lists.concat(res.data.result.param);
}
})
.catch(err => {
console.log(err);
})
},*/
handleScroll() {
console.log('進入滾動事件監聽');
var that = this;
let s_top = document.documentElement.scrollTop;
let d_height = document.body.clientHeight-document.documentElement.clientHeight -10;
console.log('可视高度'+s_top,'超出可视高度'+d_height);
if(that.isTrue){
if(s_top >= d_height){
console.log('可以加载数据了')
this.isShow = true;
setTimeout(()=>{
that.page++;
// alert('ded');
console.log(that.page)
that.getInfo();
},1000);
that.isTrue=false;
}
}
//判断滚动到底部
/*if ($(window).scrollTop() >= $(document).height() - $(window).height()) {
if (that.isTrue) {
setTimeout(function() {
}, 1000);
that.isTrue = false;
}
}*/
}
},
mounted() {
window.addEventListener('scroll',this.handleScroll) ;
// window.addEventListener('touchmove', this.handleScroll)
},
computed: {
current() {
return this.$store.state.current;
}
}
}
</script>
<style scoped>
.three {
background: greenyellow;
/*height: 700px;*/
}
.box {
width: 80%;
margin: 0 auto 20px;
border-radius: 10px;
background: #f0f0f0;
height: 200px;
text-align: center;
}
</style>