提交 474b268d authored 作者: caicai's avatar caicai

无限加载+懒加载图片

上级 8225fa36
<template> <template>
<div> <div v-infinite-scroll="loadNext">
<box v-if="listObj && listObj.lastest"> <box v-if="listObj && listObj.lastest">
<item v-for="(lItem,lIndex) in listObj.lastest" :key="lIndex" <item v-for="(lItem,lIndex) in currentList" :key="lIndex"
:src="lItem.icon" :src="lItem.icon"
:name="lItem.name" :name="lItem.name"
:detail="lItem" :detail="lItem"
...@@ -136,19 +136,46 @@ export default { ...@@ -136,19 +136,46 @@ export default {
top:0, top:0,
current:-1, current:-1,
id:-1, id:-1,
},
currentList:[],
pageData: {
page:1,
total:-1,
} }
}; };
}, },
computed: { computed: {
},
watch: {
'listObj.lastest' : {
handler(n) {
this.pageData.total = this.listObj && this.listObj.lastest.length || 0;
if(this.currentList.length == 0) {
this.currentList = this.listObj && this.listObj.lastest.slice(0,19);
}
},
immediate:true,
deep:true
}
}, },
created() { created() {
this.listener(); this.listener();
this.currentList = this.listObj && this.listObj.lastest.slice(0,19);
}, },
destroyed() { destroyed() {
window.removeEventListener("contextmenu",this.handleEvent) window.removeEventListener("contextmenu",this.handleEvent)
}, },
methods: { methods: {
loadNext() {
if(this.currentList.length >= this.pageData.total && this.pageData.total != 0) {
return;
}
// 加载下一页
this.pageData.page ++ ;
let newData = this.listObj.lastest.slice((this.pageData.page-1)*18+1,(this.pageData.page*18 + 1));
this.currentList = this.currentList.concat(newData);
},
findParentEl({dataType, element, className}) { findParentEl({dataType, element, className}) {
if(dataType) { if(dataType) {
if(element.dataset.type === dataType) return element; if(element.dataset.type === dataType) return element;
...@@ -161,7 +188,6 @@ export default { ...@@ -161,7 +188,6 @@ export default {
return null; return null;
}, },
handleEvent(e) { handleEvent(e) {
console.dir(e)
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
if(e.target.dataset.type === 'closeMask' || this.showMenu) { if(e.target.dataset.type === 'closeMask' || this.showMenu) {
......
<template> <template>
<div v-if="src && (src.indexOf('data:image/svg') == 0 || src.indexOf('data:image/png') == 0)" <div v-if="src && (src.indexOf('data:image/svg') == 0 || src.indexOf('data:image/png') == 0)"
class="item_wrap" @click="tapApp" data-type="right-menu" :data-id="detail.id" :data-index="index"> class="item_wrap" @click="tapApp" data-type="right-menu" :data-id="detail.id" :data-index="index">
<img :src="src" alt="" class="item_img"> <!-- <img :src="src" alt="" class="item_img" lazy> -->
<el-image :src="src" alt="" class="item_img" :lazy="index>18"></el-image>
<span class="item_name">{{name}}</span> <span class="item_name">{{name}}</span>
</div> </div>
</template> </template>
......
...@@ -13,24 +13,24 @@ module.exports = { ...@@ -13,24 +13,24 @@ module.exports = {
VERSION: JSON.stringify(machineIdSync({original: true})) VERSION: JSON.stringify(machineIdSync({original: true}))
}) })
], ],
devtool: 'source-map', // 'source-map' \ false // devtool: 'source-map', // 'source-map' \ false
optimization: { // optimization: {
minimize: true, // minimize: true,
minimizer: [ // minimizer: [
new TerserPlugin({ // 要引用 TerserPlugin // new TerserPlugin({ // 要引用 TerserPlugin
terserOptions: { // terserOptions: {
ecma: undefined, // ecma: undefined,
warnings: false, // warnings: false,
parse: {}, // parse: {},
compress: { // compress: {
drop_console: true, // drop_console: true,
drop_debugger: false, // drop_debugger: false,
pure_funcs: ['console.log'] // 移除console // pure_funcs: ['console.log'] // 移除console
} // }
}, // },
}), // }),
], // ],
} // }
}, },
pages: { pages: {
app: { app: {
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论