-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweather.html
More file actions
111 lines (99 loc) · 2.96 KB
/
weather.html
File metadata and controls
111 lines (99 loc) · 2.96 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
}
h2 {
text-align: center;
font-size: 30px;
margin-top: 15px;
margin-bottom: 20px;
}
body>div {
text-align: center;
}
input {
width: 300px;
height: 20px;
margin-right: 10px;
margin-bottom: 10px;;
border: 1px solid skyblue;
}
img {
width: 250px;
height: 200px;
display: block;
text-align: center;
background-repeat: no-repeat;
margin: 0 auto;
}
ul {
margin: 0;
margin-right: 10px;
width: 150px;
float: left;
height: 100%;
}
li {
padding-top: 20px;
text-align: center;
list-style: none;
margin-right: 10px;
}
.result {
margin: 20px auto;
width: 800px;
height: 250px;
}
</style>
</head>
<body>
<img src="https://img0.baidu.com/it/u=3605006026,2273382621&fm=26&fmt=auto&gp=0.jpg">
<h2>全国各地城市天气查询</h2>
<div id="app">
<input type="text" v-model="searchKey" @keyup.enter="query" placeholder="请输入城市名">
<button @click="query">搜索</button>
<div class="result">
<ul v-for='item in weather_list'>
<li><b>{{item.date}}</b></li>
<li>{{item.fengxiang}}</li>
<li style="color:red">{{item.high}}</li>
<li style="color:blue">{{item.low}}</li>
<li>{{item.type}}</li>
</ul>
</div>
</div>
<script>
var app = new Vue({
el:"#app",
data:{
weather_list:[],
searchKey:''
},
methods: {
query: function() {
that = this;
if (that.searchKey == '') {
that.weather_list = [];
return;
}
axios.get("http://wthrcdn.etouch.cn/weather_mini?city="+that.searchKey).then(function(response) {
that.weather_list = response.data.data.forecast;
}).catch( function(err) {
alert('未找到,请输入正确中文名称')
});
}
}
});
</script>
</body>
</html>