xxxxxxxxxx
1
<template>
2
<MDBContainer
3
class="mt-5"
4
style="height: 500px; overflow-y: scroll"
5
id="lazy-container-1"
6
>
7
<MDBRow class="text-center" style="height: 800px">
8
<p>Scroll down to see an image</p>
9
<MDBBtn @click="handleClick" color="primary">Change lazySrc</MDBBtn>
10
<p><i class="far fa-arrow-alt-circle-down fa-3x my-4"></i></p>
11
<img
12
v-if="shouldRender"
13
v-mdb-lazy="directiveData"
14
alt="Example image"
15
class="img-fluid lazy my-3"
16
style="margin-top: 50% !important"
17
/>
18
<img
19
v-if="shouldRender"
20
v-mdb-lazy="directiveData"
21
alt="Example image"
22
class="img-fluid lazy my-3"
23
style="margin-top: 50% !important"
24
/>
25
</MDBRow>
26
</MDBContainer>
27
</template>
xxxxxxxxxx
1
<style>
2
#app {
3
font-family: Roboto, Helvetica, Arial, sans-serif;
4
}
5
</style>
xxxxxxxxxx
1
<script>
2
import { mdbLazy, MDBContainer, MDBRow, MDBBtn } from 'mdb-vue-ui-kit';
3
import { ref, computed } from "vue"
4
5
export default {
6
directives: {
7
mdbLazy
8
},
9
components: {
10
MDBContainer,
11
MDBRow,
12
MDBBtn
13
},
14
setup() {
15
const srcData = ref('https://mdbootstrap.com/img/Photos/Slides/img%20(102).webp')
16
const shouldRender = ref(true);
17
18
const directiveData = computed(() => { return {
19
src: srcData.value,
20
placeholder: 'https://place-hold.it/1321x583?text=Loading',
21
parent: '#lazy-container-1'
22
}});
23
24
const handleClick = () => {
25
shouldRender.value = false;
26
srcData.value = 'https://mdbootstrap.com/img/Photos/Slides/img%20(103).webp'
27
28
setTimeout(()=>{
29
shouldRender.value = true;
30
},10)
31
}
32
33
34
35
36
return {
37
handleClick, directiveData, shouldRender
38
}
39
}
40
};
41
</script>
Console errors: 0