-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.vue
115 lines (115 loc) · 2.94 KB
/
index.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<template>
<div>
<list>
<refresh class="refresh" @refresh="onrefresh" @pullingdown="onpullingdown" :display="refreshing">
<text class="indicator">Refreshing ...</text>
</refresh>
<cell v-for="news in newslist">
<div class="panel">
<text class="text">{{news.newsTitle}}</text>
<text class="content">{{news.newsContent}}</text>
</div>
</cell>
<loading class="loading" @loading="onloading" :display="showLoading">
<text class="indicator">Loading...</text>
</loading>
</list>
</div>
</template>
<style scoped>
.panel{
width:600px;
height:250px;
margin-left:75px;
margin-top:35px;
margin-bottom:35px;
flex-direction: column;
justify-content: center;
border-width: 2px;
border-style: solid;
border-color:rgb(162,217,192);
background-color:rgba(162, 217, 192, 0.2);
padding-top:15px;
padding-left:10px;
padding-right:10px;
}
.text{
font-size:50px;
text-align: center;
color:#41B883;
}
.indicator{
font-size: 42px;
text-align: center;
}
.content{
lines:3;
font-size: 28px;
}
</style>
<script>
const modal = weex.requireModule('modal');
//用于实现网络请求
const stream = weex.requireModule('stream');
export default {
data () {
return {
newslist:[],
showLoading:"hide",
refreshing:"hide",
newsData:[],
}
},
created(){
let url="http://www.jspang.com/DemoApi/newsApi.php";
this.getUrl(url,res=>{
modal.toast({
message:"请求成功!",
duration: 1
});
this.newslist=res.data;
this.newsData=res.data;
console.log(res.data);
});
},
methods:{
getUrl(url,callback){
return stream.fetch({
method:'GET',
type:'json',
url:url
},callback)
},
//下拉加载
onloading(event) {
modal.toast({ message: 'loading', duration: 1 });
this.showLoading = 'show';
setTimeout(() => {
const length = this.newslist.length;
for (let i = length; i < length + 4; i++) {
this.newslist.push(i + 1);
}
this.showLoading = 'hide';
}, 1500)
},
//上拉刷新
onrefresh(event){
modal.toast({message:'refresh',duration:1});
this.refreshing="show";
setTimeout(() => {
this.newslist=this.newsData;
this.refreshing="hide";
}, 1500);
},
//上拉刷新(只拉一点也能刷新,不用拉到底)
onpullingdown(event){
modal.toast({message:'onpullingdown',duration:1});
this.refreshing="show";
setTimeout(() => {
this.newslist=this.data;
this.refreshing="hide";
}, 1500);
}
}
}
</script>