vue天气查询
天气查询包括回车查询和点击查询两种功能
回车查询
1.按下回车(v-on+.enter)
2.查询数据(axios+接口+v-model)
3.渲染数据(v-for+arr)
点击查询
1.点击城市查询(v-on+自定义参数)
2.查询数据(this.)
3.渲染数据(this.)
<template>
<div id="app">
<div>
<div id="one">
<input type="text" v-model="city" placeholder="请输入需要查询城市名" @keyup.enter="search" /><button @click="search">搜索</button>
</div>
<div id="two">
<a href="javascript:;" @click="change('北京')">北京</a>
<a href="javascript:;" @click="change('上海')">上海</a>
<a href="javascript:;" @click="change('广州')">广州</a>
<a href="javascript:;" @click="change('深圳')">深圳</a>
</div>
<ul id="three">
<li v-for="value in wList">
<div>
<span>{{value.type}}</span>
</div>
<div>
<b>{{value.low}}</b>
~
<b>{{value.high}}</b>
</div>
<div>
<span>{{value.date}}</span>
</div>
</li>
</ul>
</div>
</div>
</template> <script>
export default {
name: "App",
data: () => {
return {
city: "",
wList: []
};
},
methods: {
search: function() {
console.log(this.city);
var that = this;
this.$axios({
url: "http://wthrcdn.etouch.cn/weather_mini?city=" + this.city,
methods: "get"
})
.then(function(response) {
// console.log(response.data.data.forecast)
that.wList = response.data.data.forecast;
})
.catch(function(err) {});
},
change: function(city) {
this.city = city;
// methods中定义的方法内部,可以通过this关键字调用其他的方法
this.search();
}
},
created: function() {}
};
</script> <style>
#app {
font-family: "Avenir", Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
} ul,
li {
list-style: none;
padding: 0;
}
#app>div{
width: 900px;
margin: 0 auto;
}
#one{
text-align: left;
margin-left: 150px;
}
#one input{
width: 400px;
height: 30px;
border: 2px solid #ccc;
}
#one button{
width: 80px;
height: 35px;
background-color: #0af;
border: 0;
}
#two{
text-align: left;
margin-bottom: 40px;
margin-left: 155px;
margin-top: 5px;
}
#two a{
color: rgb(102, 99, 99);
text-decoration: none;
font-size: 14px;
}
#three li{
float: left;
border-right: 2px solid #ccc;
padding: 6px;
}
#three li:first-child{
padding-left:0;
}
#three li:last-child{
border: 0
}
li div{
margin: 10px 0;
}
li div:first-child span{
font-size: 20px;
color: #ef7000;
font-weight: bold;
}
li div:first-child{
margin-top: 0
}
li div:last-child span{
font-size: 14px;
color: #999;
}
li div:last-child {
margin-bottom: 0
}
</style>
vue天气查询的更多相关文章
- 基于node的cmd迷你天气查询工具
1.前几天网上看到的,于是自己小改了一下,更换了天气查询的接口,当作练习一下node. 2.收获挺大的,捣鼓了一天,终于学会了发布npm包. 3.接下来,就介绍一下这个 mini-tianqi 的主要 ...
- H5天气查询demo(二)
最近刚好有空,学长帮忙让做个毕设,于是我提到了那个基于H5地理位置实现天气查询的方法,学长听了也觉得不错,于是就这个主题,扩展了一下,做了一个航班管理查询系统,为上次博客中提到的利用H5 api中的经 ...
- C#调用天气查询服务
先引入天气查询服务 1.有点引用导入服务引用 //实例化 web引用名.WeatherWebService cn = new web引用名.WeatherWebService() ...
- 【转】根据中国气象局提供的API接口实现天气查询
本文转载自 老三 的 三叶草 中国气象局提供了三个天气查询的API接口: [1]http://www.weather.com.cn/data/sk/101190101.html [2]http://w ...
- 天气查询SDK
简介: 这是一个用于查询天气的SDK,在很多时候,尤其是对接多而小功能公众账号的时候,天气查询比较使用,此SDK就是这样的用途,使用的是中国天气网的API,已经集成了网上最靠谱的方式来实现,包括里面的 ...
- Android 身份证号码查询、手机号码查询、天气查询
1.基本信息 身份证号码查询:http://apistore.baidu.com/apiworks/servicedetail/113.html 手机号码:http://apistore.baidu. ...
- 根据中国气象局提供的API接口实现天气查询
中国气象局提供了三个天气查询的API接口: [1]http://www.weather.com.cn/data/sk/101190101.html [2]http://www.weather.com. ...
- 05_天气查询_JAX-WS方式_客户端
[客户端特点] 支持面向对象开发. 客户端功能调用webService,首先得知道WebService的地址. 一般情况下,只要知道了wsdl的地址,就可以知道WebService的地址. 我们上一篇 ...
- 03_天气查询_socket方式模拟_多线程方式
[简述] 要重视Socket开发,企业后台服务特长使用Socket. 1.服务端要有可持续运行能力,保证线程一致在运行 2.并发处理能力,使用多线程 [工程截图] [WeatherRunner.jav ...
随机推荐
- cmd 下sql语句及结果
Microsoft Windows [版本 10.0.14393](c) 2016 Microsoft Corporation.保留所有权利. C:\Users\李长青>mysql -uroot ...
- navicat永久激活
https://jingyan.baidu.com/article/f54ae2fc51f0311e92b84998.html
- Windows中配置maven环境变量
添加maven环境变量 添加新的系统环境变量:MAVEN_HOME 设置其值为你安装的目录:D:\IT_program\apache-maven-3.6.0 更新系统PATH 变量 添加变量值:%MA ...
- 三行代码实现垂直居中和cube
三行代码实现上下居中 position: relative;top: 50%;transform: translateY(-50%); 效果如下: 代码: <!DOCTYPE html> ...
- C++——指针4
8.对象指针 声明: 类名 *对象指针名 Point A(5,10): Point *ptr; ptr=&A;//通过指针访问对象成员:对象指针名->成员名.ptr->getX( ...
- 修改json数据中key(键值)
//方法一:修改JSONObject的键 public static JSONObject changeJsonObj(JSONObject jsonObj,Map<String, String ...
- Java实现图形界面的三部曲及IDE中的窗口设计
设计和实现图形用户界面的工作主要有以下几点: • (1)创建组件(Component) • 创建组成界面的各种元素,如按钮.文本框等.• (2)指定布局(Layout) • 根据具体需要排列它们的位置 ...
- bash数学运算之bc
一.expr 1.1 语法 注意必须有空格 只能精确到整数,无法精确到浮点数 1.2 操作符对照表 使用expr命令时需要加\进行转义,因为部分符号是保留关键字 例1:比较num1跟num2的大小 [ ...
- eslint全局变量报错 xxx is not defined
找到.eslintrc.js,添加 "globals": { "你的全局变量": true }, 如果globals已经存在在里边加入你要忽略检测的全局变量即可 ...
- php设计模式之适配器模式实例代码
<?php header("Content-type:text/html;charset=utf-8"); // 适配器模式 /** * 查看天气接口 */ class Ti ...