Skip to content

Commit

Permalink
使用 mint-ui 做 Infinite scroll,实现数据加载
Browse files Browse the repository at this point in the history
  • Loading branch information
no1harm committed Oct 31, 2018
1 parent c4fe639 commit 27c3155
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 12 deletions.
16 changes: 14 additions & 2 deletions .babelrc
Expand Up @@ -8,5 +8,17 @@
}],
"stage-2"
],
"plugins": ["transform-vue-jsx", "transform-runtime"]
}
"plugins": [
"transform-vue-jsx",
"transform-runtime",
[
"component",
[
{
"libraryName": "mint-ui",
"style": true
}
]
]
]
}
38 changes: 38 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -10,6 +10,7 @@
"build": "node build/build.js"
},
"dependencies": {
"mint-ui": "^2.2.13",
"vue": "^2.5.2",
"vue-router": "^3.0.1"
},
Expand All @@ -18,6 +19,7 @@
"babel-core": "^6.22.1",
"babel-helper-vue-jsx-merge-props": "^2.0.3",
"babel-loader": "^7.1.1",
"babel-plugin-component": "^1.1.1",
"babel-plugin-syntax-jsx": "^6.18.0",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-plugin-transform-vue-jsx": "^3.5.0",
Expand Down
8 changes: 6 additions & 2 deletions src/pages/index/index.html
Expand Up @@ -74,7 +74,11 @@
</div>
</div>
<div class="hot-goods js-waterfull-wrap" data-src="">
<ul class="js-list js-lazy" data-src="">
<ul class="js-list js-lazy"
data-src=""
v-infinite-scroll="getLists"
infinite-scroll-disabled="loading"
infinite-scroll-distance="20">
<li v-for='list in lists' :key='list.id'>
<div class="goods-item">
<a href="https://h5.youzan.com/v2/showcase/goods?alias=2fwig6rnqfq6m&amp;source=yzapp&amp;f_platform=yzapp">
Expand All @@ -89,7 +93,7 @@
</div>
</li>
</ul>
<div class="loading-more"><span></span></div>
<div class="loading-more" v-show='loading'><span></span></div>
</div>
<div class="js-show-find category-guid" style="display: none;"></div>
</div>
Expand Down
40 changes: 32 additions & 8 deletions src/pages/index/index.js
Expand Up @@ -3,19 +3,43 @@ import './index.css'
import Vue from 'vue'
import axios from 'axios'
import url from 'js/api.js'
import { InfiniteScroll } from 'mint-ui'
Vue.use(InfiniteScroll)

let app = new Vue({
el:'#app',
data:{
lists:null
lists:null,
pageNum:1,
pageSize:6,
loading:false,
allLoaded:false
},
created() {
axios.post(url.hotLists,{
pageNum:1,
pageSize:6
}).then(res=>{
this.lists = res.data.lists
console.log(this.lists)
})
this.getLists()
},
methods:{
getLists(){
if(this.allLoaded) return
this.loading = true
axios.post(url.hotLists,{
pageNum:this.pageNum,
pageSize:this.pageSize
}).then(res=>{
let curLists = res.data.lists
// 判断所有数据是否加载完毕
if(curLists.length < this.pageSize){
this.allLoaded = true
}
if(this.lists){
this.lists = this.lists.concat(curLists)
}else{
// 第一次请求数据
this.lists = res.data.lists
}
})
this.loading = false
this.pageNum ++
}
}
})

0 comments on commit 27c3155

Please sign in to comment.