-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlifeCycleHook.html
87 lines (84 loc) · 2.34 KB
/
lifeCycleHook.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Scroller</title>
<style>
.button-bottom {
position: fixed;
right: 10vw;
bottom: 10vh;
}
</style>
</head>
<body>
<div id="app">
<button @click="scrollToTop" class="button-bottom">^</button>
<div v-for="photo in photos">
<h5>{{ photo.title }}</h5>
<img :src="photo.thumbnailUrl" :alt="photo.title">
</div>
<div id="bottomSensor"></div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/scrollmonitor/1.2.0/scrollMonitor.js"></script>
<script>
const app = new Vue({
el: '#app',
data: {
photos: [],
page: 1
},
methods: {
getPhotos: function () {
const options = {
params: {
_page: this.page++,
_limit: 3,
}
}
axios.get('https://jsonplaceholder.typicode.com/photos', options)
.then((res)=>{
console.log('>>>GET PHOTOS<<<')
this.photos = [...this.photos, ...res.data]
})
},
addScrollWatcher: function () {
const bottomSensor = document.querySelector('#bottomSensor')
const watcher = scrollMonitor.create(bottomSensor)
watcher.enterViewport(()=>{
console.log('____BOTTOM____')
setTimeout(()=>{
this.getPhotos()
}, 500)
})
},
scrollToTop: function () {
scroll(0, 0)
},
loadUntilViewportIsFull: function () {
const bottomSensor = document.querySelector('#bottomSensor')
const watcher = scrollMonitor.create(bottomSensor)
if (watcher.isFullyInViewport) {
this.getPhotos()
}
}
},
created: function () {
console.log('응애')
// this.getPhotos()
},
mounted: function () {
console.log('DOM에 부착되었다!')
this.addScrollWatcher()
},
updated: function () {
console.log('updated 되었다!')
this.loadUntilViewportIsFull()
}
})
</script>
</body>
</html>