Commit b27c963a authored by duanledexianxianxian's avatar duanledexianxianxian 😁

sync

parent 9369e86c
<template> <template>
<div class="root"> <div class="root">
<van-search v-model="value" placeholder="请输入搜索关键词" /> <van-search placeholder="请输入搜索关键词" />
<div class="list"> <div class="list">
<van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad"> <van-list v-model="loading" :finished="listFinished" finished-text="没有更多了" @load="handleLoad">
<div class="item" v-for="(item,index) in list" :key="index"> <div class="item" v-for="(item) in dataSouce" :key="item.id">
<img src="@/assets/images/exam1.png" /> <img src="@/assets/images/exam1.png" />
<div class="right"> <div class="right">
<div class="title">{{item.title}}</div> <div class="title">{{item.title}}</div>
<div class="action"> <div class="action">
<div class="like flex-space-around"> <div class="like flex-space-around">
<van-icon name="like" size="24" :color="item.like===0? '#ff7b7b':'#cccccc'" /> <van-icon
name="like"
size="24"
:color="item.like===0? '#ff7b7b':'#cccccc'"
@click="handelLike(item.id)"
/>
<div class="label">收藏</div> <div class="label">收藏</div>
</div> </div>
<div class="share flex-space-around"> <div class="share flex-space-around">
<van-icon name="share" size="24" color="#cccccc" /> <van-icon name="share" size="24" color="#cccccc" @click="handleShare(item.id)" />
<div class="label">分享</div> <div class="label">分享</div>
</div> </div>
<div class="answer"> <div class="answer">
...@@ -28,34 +33,47 @@ ...@@ -28,34 +33,47 @@
</template> </template>
<script> <script>
export default { export default {
props: {
type: {
type: Number,
default: 0
},
loading: {
type: Boolean,
default: false
},
finished: {
default: false
},
list: {
default: []
},
onLoad:Function
},
data() { data() {
return { return {
list: [], listLoading:this.loading,
loading: false, listFinished:this.finished,
finished: false dataSouce:this.list
}; };
}, },
methods: { methods: {
onLoad() { handleLoad(e) {
// 异步更新数据 this.onLoad(e)
// setTimeout 仅做示例,真实场景中一般为 ajax 请求 },
setTimeout(() => { // 处理收藏
for (let i = 0; i < 10; i++) { handleLike(id) {
this.list.push({ const index = this.dataSource.findIndex(value => value === id);
id: i, if (index > -1) {
like: i % 3 === 0 ? 1 : 0, return
title: "2020版中西医结合执业助理医师 模拟试" }
}); },
} // 处理分享
handleShare(id) {
// 加载状态结束 const index = this.dataSource.findIndex(value => value === id);
this.loading = false; if (index > -1) {
return
// 数据全部加载完成 }
if (this.list.length >= 40) {
this.finished = true;
}
}, 1000);
} }
} }
}; };
...@@ -77,7 +95,7 @@ export default { ...@@ -77,7 +95,7 @@ export default {
display: flex; display: flex;
margin: 0 8px 24px; margin: 0 8px 24px;
justify-content: space-between; justify-content: space-between;
img { img {
height: 92px; height: 92px;
width: 120px; width: 120px;
......
...@@ -26,7 +26,7 @@ export default { ...@@ -26,7 +26,7 @@ export default {
}, },
data() { data() {
return { return {
active: 2 active: 0
}; };
} }
}; };
......
<template> <template>
<div class="root"> <div class="root">
<List></List> <List :list="list" :loading="loading" :finished="finished" :onLoad="loadData"></List>
</div> </div>
</template> </template>
<script> <script>
...@@ -8,6 +8,41 @@ import List from "../components/List"; ...@@ -8,6 +8,41 @@ import List from "../components/List";
export default { export default {
components: { components: {
List List
},
data() {
return {
list:[],
loading:false,
finished:false
};
},
created() {
// 加载数据
// this.loadData();
},
methods: {
// 加载数据
loadData: function(){
// 异步更新数据
// setTimeout 仅做示例,真实场景中一般为 ajax 请求
setTimeout(() => {
for (let i = 0; i < 3; i++) {
this.list.push({
id: i,
like: i % 3 === 0 ? 1 : 0,
title: "2020版中西医结合执业助理医师 模拟试"
});
}
// 加载状态结束
this.loading = false;
// 数据全部加载完成
if (this.list.length >= 40) {
this.finished = true;
}
}, 1000);
}
} }
}; };
</script> </script>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment