vue-网络应用-天气查询(axios)

axios.get().then(function(response){}).catch(function(err){})
get()发送请求,中间写请求地址
then()成功的回调函数
catch()失败的回调函数
输入城市按回车查询
注:
在回调函数中不能直接用this赋值,应先把this赋值给函数内的变量,再在回调函数中调用这个变量去改变他的值

axios的在线cdn:https://cdn.staticfile.org/axios/0.18.0/axios.min.js

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<div id="app">
			<h2>天气查询</h2>
			<input type="text" v-model="city" @keyup.enter="search" >
			<table v-if="list.length>0" >
				<tr v-for="item in list">
					<td>{{item.date}}</td>
					<td>{{item.high}}</td>
					<td>{{item.fengli}}</td>
					<td>{{item.low}}</td>
					<td>{{item.type}}</td>
					<td>{{item.fengxiang}}</td>
				</tr>
			</table>
		</div>
		<script src="js/vue.js"></script>
		<script src="https://cdn.staticfile.org/axios/0.18.0/axios.min.js"></script>
		<script>
			var app = new Vue({
				el:"#app",
				data:{
					list: [],
					city:''
				},
				methods:{
					search:function(){
						var that = this;
						axios.get('http://wthrcdn.etouch.cn/weather_mini?city='+this.city).then(function(response){
							console.log(response);
							that.list = response.data.data.forecast;
							console.log(that.list[0]);
						}).catch(function(err){
							console.log(err)
						})	
					}
				}
			})
		</script>
	</body>
</html>

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值