Implemented DeferredContent component
parent
c24185c26c
commit
1f97d2f1f8
|
@ -0,0 +1 @@
|
||||||
|
export * from './components/deferredcontent/DeferredContent';
|
|
@ -0,0 +1,3 @@
|
||||||
|
'use strict';
|
||||||
|
module.exports = require('./components/deferredcontent/DeferredContent.vue');
|
||||||
|
|
|
@ -75,9 +75,10 @@
|
||||||
<div>
|
<div>
|
||||||
<router-link to="/accordion">● Accordion</router-link>
|
<router-link to="/accordion">● Accordion</router-link>
|
||||||
<router-link to="/card">● Card</router-link>
|
<router-link to="/card">● Card</router-link>
|
||||||
<router-link to="/panel">● Panel</router-link>
|
<router-link to="/deferredcontent">● Deferred</router-link>
|
||||||
<router-link to="/fieldset">● Fieldset</router-link>
|
<router-link to="/fieldset">● Fieldset</router-link>
|
||||||
<router-link to="/flexgrid">● FlexGrid</router-link>
|
<router-link to="/flexgrid">● FlexGrid</router-link>
|
||||||
|
<router-link to="/panel">● Panel</router-link>
|
||||||
<router-link to="/tabview">● TabView</router-link>
|
<router-link to="/tabview">● TabView</router-link>
|
||||||
<router-link to="/toolbar">● Toolbar</router-link>
|
<router-link to="/toolbar">● Toolbar</router-link>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
import Vue, {VNode} from 'vue';
|
||||||
|
|
||||||
|
export declare class DeferredContent extends Vue {
|
||||||
|
$emit(eventName: 'load'): this;
|
||||||
|
$slots: {
|
||||||
|
'': VNode[];
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,66 @@
|
||||||
|
<template>
|
||||||
|
<div ref="container">
|
||||||
|
<slot v-if="loaded"></slot>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
loaded: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
if (!this.loaded) {
|
||||||
|
if (this.shouldLoad())
|
||||||
|
this.load();
|
||||||
|
else
|
||||||
|
this.bindScrollListener();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
beforeDestroy() {
|
||||||
|
this.unbindScrollListener();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
bindScrollListener() {
|
||||||
|
this.documentScrollListener = () => {
|
||||||
|
if (this.shouldLoad()) {
|
||||||
|
this.load();
|
||||||
|
this.unbindScrollListener();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener('scroll', this.documentScrollListener);
|
||||||
|
},
|
||||||
|
unbindScrollListener() {
|
||||||
|
if (this.documentScrollListener) {
|
||||||
|
window.removeEventListener('scroll', this.documentScrollListener);
|
||||||
|
this.documentScrollListener = null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
shouldLoad() {
|
||||||
|
if (this.loaded) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const rect = this.$refs.container.getBoundingClientRect();
|
||||||
|
const docElement = document.documentElement;
|
||||||
|
const winHeight = docElement.clientHeight;
|
||||||
|
|
||||||
|
return (winHeight >= rect.top);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
load() {
|
||||||
|
this.loaded = true;
|
||||||
|
this.$emit('load', event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
this.unbindScrollListener();
|
||||||
|
}
|
|
@ -14,6 +14,7 @@ import Column from './components/column/Column';
|
||||||
import DataTable from './components/datatable/DataTable';
|
import DataTable from './components/datatable/DataTable';
|
||||||
import DataView from './components/dataview/DataView';
|
import DataView from './components/dataview/DataView';
|
||||||
import DataViewLayoutOptions from './components/dataviewlayoutoptions/DataViewLayoutOptions';
|
import DataViewLayoutOptions from './components/dataviewlayoutoptions/DataViewLayoutOptions';
|
||||||
|
import DeferredContent from './components/deferredcontent/DeferredContent';
|
||||||
import Dialog from './components/dialog/Dialog';
|
import Dialog from './components/dialog/Dialog';
|
||||||
import Dropdown from './components/dropdown/Dropdown';
|
import Dropdown from './components/dropdown/Dropdown';
|
||||||
import Editor from './components/editor/Editor';
|
import Editor from './components/editor/Editor';
|
||||||
|
@ -78,6 +79,7 @@ Vue.component('Column', Column);
|
||||||
Vue.component('DataTable', DataTable);
|
Vue.component('DataTable', DataTable);
|
||||||
Vue.component('DataView', DataView);
|
Vue.component('DataView', DataView);
|
||||||
Vue.component('DataViewLayoutOptions', DataViewLayoutOptions);
|
Vue.component('DataViewLayoutOptions', DataViewLayoutOptions);
|
||||||
|
Vue.component('DeferredContent', DeferredContent);
|
||||||
Vue.component('Dialog', Dialog);
|
Vue.component('Dialog', Dialog);
|
||||||
Vue.component('Dropdown', Dropdown);
|
Vue.component('Dropdown', Dropdown);
|
||||||
Vue.component('Editor', Editor);
|
Vue.component('Editor', Editor);
|
||||||
|
|
|
@ -165,6 +165,11 @@ export default new Router({
|
||||||
path: '/dataview',
|
path: '/dataview',
|
||||||
name: 'dataview',
|
name: 'dataview',
|
||||||
component: () => import('./views/dataview/DataViewDemo.vue')
|
component: () => import('./views/dataview/DataViewDemo.vue')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/deferredcontent',
|
||||||
|
name: 'deferredcontent',
|
||||||
|
component: () => import('./views/deferredcontent/DeferredContentDemo.vue')
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/dialog',
|
path: '/dialog',
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<div class="content-section introduction">
|
||||||
|
<div class="feature-intro">
|
||||||
|
<h1>DeferredContent</h1>
|
||||||
|
<p>DeferredContent postpones the loading the content that is initially not in the viewport until it becomes visible on scroll..</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="content-section implementation">
|
||||||
|
<div style="height: 800px">
|
||||||
|
Scroll down to lazy load an image and the DataTable which initiates a query that is not executed on initial page load to speed up load performance.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DeferredContent @load="onImageLoad">
|
||||||
|
<img src="demo/images/nature/nature4.jpg" alt="Nature"/>
|
||||||
|
</DeferredContent>
|
||||||
|
|
||||||
|
<div style="height: 500px">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DeferredContent @load="onDataLoad">
|
||||||
|
<DataTable :value="cars">
|
||||||
|
<Column field="vin" header="Vin"></Column>
|
||||||
|
<Column field="year" header="Year"></Column>
|
||||||
|
<Column field="brand" header="Brand"></Column>
|
||||||
|
<Column field="color" header="Color"></Column>
|
||||||
|
</DataTable>
|
||||||
|
</DeferredContent>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DeferredContentDoc />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<script>
|
||||||
|
import CarService from '../../service/CarService';
|
||||||
|
import DeferredContentDoc from './DeferredContentDoc';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
cars: null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
carService: null,
|
||||||
|
created() {
|
||||||
|
this.carService = new CarService();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onImageLoad() {
|
||||||
|
this.$toast.add({severity: 'success', summary: 'Image Initialized', detail: 'Scroll down to load the datatable'});
|
||||||
|
},
|
||||||
|
onDataLoad() {
|
||||||
|
this.carService.getCarsSmall().then(data => this.cars = data);
|
||||||
|
this.$toast.add({severity: 'success', summary: 'Data Initialized', detail: 'Render Completed'});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
components: {
|
||||||
|
'DeferredContentDoc': DeferredContentDoc
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
|
@ -0,0 +1,136 @@
|
||||||
|
<template>
|
||||||
|
<div class="content-section documentation">
|
||||||
|
<TabView>
|
||||||
|
<TabPanel header="Documentation">
|
||||||
|
<h3>Import</h3>
|
||||||
|
<CodeHighlight lang="javascript">
|
||||||
|
import DeferredContent from 'primevue/deferredcontent';
|
||||||
|
</CodeHighlight>
|
||||||
|
|
||||||
|
<h3>Getting Started</h3>
|
||||||
|
<p>DeferredContent is used as a wrapper element of its content..</p>
|
||||||
|
<CodeHighlight>
|
||||||
|
<template v-pre>
|
||||||
|
<DeferredContent>
|
||||||
|
<DataTable :value="cars">
|
||||||
|
<Column field="vin" header="Vin"></Column>
|
||||||
|
<Column field="year" header="Year"></Column>
|
||||||
|
<Column field="brand" header="Brand"></Column>
|
||||||
|
<Column field="color" header="Color"></Column>
|
||||||
|
</DataTable>
|
||||||
|
</DeferredContent>
|
||||||
|
</template>
|
||||||
|
</CodeHighlight>
|
||||||
|
|
||||||
|
<h3>Load Event</h3>
|
||||||
|
<p>onLoad callback is useful to initialize the content when it becomes visible on scroll such as loading data.</p>
|
||||||
|
<CodeHighlight>
|
||||||
|
<template v-pre>
|
||||||
|
<DeferredContent @load="onDataLoad">
|
||||||
|
<DataTable :value="cars">
|
||||||
|
<Column field="vin" header="Vin"></Column>
|
||||||
|
<Column field="year" header="Year"></Column>
|
||||||
|
<Column field="brand" header="Brand"></Column>
|
||||||
|
<Column field="color" header="Color"></Column>
|
||||||
|
</DataTable>
|
||||||
|
</DeferredContent>
|
||||||
|
</template>
|
||||||
|
</CodeHighlight>
|
||||||
|
|
||||||
|
<h3>Properties</h3>
|
||||||
|
<p>Component has no properties.</p>
|
||||||
|
|
||||||
|
<h3>Events</h3>
|
||||||
|
<div class="doc-tablewrapper">
|
||||||
|
<table class="doc-table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Parameters</th>
|
||||||
|
<th>Description</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>load</td>
|
||||||
|
<td>event: Event object</td>
|
||||||
|
<td>Callback to invoke when deferred content is loaded..</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>Styling</h3>
|
||||||
|
<p>Component does not apply any styling.</p>
|
||||||
|
|
||||||
|
<h3>Dependencies</h3>
|
||||||
|
<p>None.</p>
|
||||||
|
</TabPanel>
|
||||||
|
|
||||||
|
<TabPanel header="Source">
|
||||||
|
<a href="https://github.com/primefaces/primevue/tree/master/src/views/deferredcontent" class="btn-viewsource" target="_blank" rel="noopener noreferrer">
|
||||||
|
<span>View on GitHub</span>
|
||||||
|
</a>
|
||||||
|
<CodeHighlight>
|
||||||
|
<template v-pre>
|
||||||
|
<div>
|
||||||
|
<div class="content-section introduction">
|
||||||
|
<div class="feature-intro">
|
||||||
|
<h1>DeferredContent</h1>
|
||||||
|
<p>DeferredContent postpones the loading the content that is initially not in the viewport until it becomes visible on scroll..</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="content-section implementation">
|
||||||
|
<div style="height: 800px">
|
||||||
|
Scroll down to lazy load an image and the DataTable which initiates a query that is not executed on initial page load to speed up load performance.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DeferredContent @load="onImageLoad">
|
||||||
|
<img src="demo/images/nature/nature4.jpg" alt="Nature"/>
|
||||||
|
</DeferredContent>
|
||||||
|
|
||||||
|
<div style="height: 500px">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DeferredContent @load="onDataLoad">
|
||||||
|
<DataTable :value="cars">
|
||||||
|
<Column field="vin" header="Vin"></Column>
|
||||||
|
<Column field="year" header="Year"></Column>
|
||||||
|
<Column field="brand" header="Brand"></Column>
|
||||||
|
<Column field="color" header="Color"></Column>
|
||||||
|
</DataTable>
|
||||||
|
</DeferredContent>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</CodeHighlight>
|
||||||
|
|
||||||
|
<CodeHighlight lang="javascript">
|
||||||
|
import CarService from '../../service/CarService';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
cars: null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
carService: null,
|
||||||
|
created() {
|
||||||
|
this.carService = new CarService();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onImageLoad() {
|
||||||
|
this.$toast.add({severity: 'success', summary: 'Image Initialized', detail: 'Scroll down to load the datatable'});
|
||||||
|
},
|
||||||
|
onDataLoad() {
|
||||||
|
this.carService.getCarsSmall().then(data => this.cars = data);
|
||||||
|
this.$toast.add({severity: 'success', summary: 'Data Initialized', detail: 'Render Completed'});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</CodeHighlight>
|
||||||
|
</TabPanel>
|
||||||
|
</TabView>
|
||||||
|
</div>
|
||||||
|
</template>
|
Loading…
Reference in New Issue