天气查询包括回车查询和点击查询两种功能

回车查询

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天气查询的更多相关文章

  1. 基于node的cmd迷你天气查询工具

    1.前几天网上看到的,于是自己小改了一下,更换了天气查询的接口,当作练习一下node. 2.收获挺大的,捣鼓了一天,终于学会了发布npm包. 3.接下来,就介绍一下这个 mini-tianqi 的主要 ...

  2. H5天气查询demo(二)

    最近刚好有空,学长帮忙让做个毕设,于是我提到了那个基于H5地理位置实现天气查询的方法,学长听了也觉得不错,于是就这个主题,扩展了一下,做了一个航班管理查询系统,为上次博客中提到的利用H5 api中的经 ...

  3. C#调用天气查询服务

    先引入天气查询服务 1.有点引用导入服务引用 //实例化            web引用名.WeatherWebService cn = new web引用名.WeatherWebService() ...

  4. 【转】根据中国气象局提供的API接口实现天气查询

    本文转载自 老三 的 三叶草 中国气象局提供了三个天气查询的API接口: [1]http://www.weather.com.cn/data/sk/101190101.html [2]http://w ...

  5. 天气查询SDK

    简介: 这是一个用于查询天气的SDK,在很多时候,尤其是对接多而小功能公众账号的时候,天气查询比较使用,此SDK就是这样的用途,使用的是中国天气网的API,已经集成了网上最靠谱的方式来实现,包括里面的 ...

  6. Android 身份证号码查询、手机号码查询、天气查询

    1.基本信息 身份证号码查询:http://apistore.baidu.com/apiworks/servicedetail/113.html 手机号码:http://apistore.baidu. ...

  7. 根据中国气象局提供的API接口实现天气查询

    中国气象局提供了三个天气查询的API接口: [1]http://www.weather.com.cn/data/sk/101190101.html [2]http://www.weather.com. ...

  8. 05_天气查询_JAX-WS方式_客户端

    [客户端特点] 支持面向对象开发. 客户端功能调用webService,首先得知道WebService的地址. 一般情况下,只要知道了wsdl的地址,就可以知道WebService的地址. 我们上一篇 ...

  9. 03_天气查询_socket方式模拟_多线程方式

    [简述] 要重视Socket开发,企业后台服务特长使用Socket. 1.服务端要有可持续运行能力,保证线程一致在运行 2.并发处理能力,使用多线程 [工程截图] [WeatherRunner.jav ...

随机推荐

  1. PHP函数对比 array_merge()与加号合并数组的区别

    首先准备两个数组,从数组索引类型分别讨论. 数组索引为字符串索引时: $a = array('a' => 1, 'b' => 2, 'c' => 3); $b = array('b' ...

  2. Echart的使用legend遇到的问题小记

    Echart的图标真的很漂亮,使用也相对简单.但是官网的配置项的例子我不是很能快速的使用,得思考一会.哈哈,可能我比较笨吧. 在作柱状图的时候,我是通过Ajax动态获取的数据,但是图例legend就是 ...

  3. linux - mysql - 卸载:RPM包安装方式的MySQL卸载

    (1)检查是否安装了MySQL组件 [root@DB-Server init.d]# rpm -qa | grep -i mysql MySQL-devel-5.6.23-1.linux_glibc2 ...

  4. IntelliJ WebStorm 2020最新 永久破解激活教程【全网最强,可用至2100年】

    说明:都到了2020年,当然要用最新的IDE,目前最新是2019.3.1版本 ①IntelliJ WebStorm 2019.3.1安装永久破解[最强] 一. 在官网下载WebStorm安装包  链接 ...

  5. python基础数据类型整理

    一.数据类型 (一).小技巧 1.PyCharm:选中多行,按"Ctrl+/"可批量注释掉 (二).字符串 1.startswith(str,[,start][,end]) #判断 ...

  6. 2019-08-09 纪中NOIP模拟B组

    T1 [JZOJ1035] 粉刷匠 题目描述 windy有N条木板需要被粉刷. 每条木板被分为M个格子. 每个格子要被刷成红色或蓝色. windy每次粉刷,只能选择一条木板上一段连续的格子,然后涂上一 ...

  7. 谷歌浏览器安装jsonview

    1.下载JsonView扩展程序压缩包 下载链接:https://pan.baidu.com/s/1B0IkrHHyTiYtwJEGE_halA 提取码:myi6 2.解压这个压缩包 3.打开谷歌浏览 ...

  8. 是未来还是“有毒”?紧抓球鞋风口的毒APP机遇与危机并存

    编辑 | 于斌 出品 | 于见(mpyujian) 新一代的"潮流"之风正在席卷新生代消费市场,从去年开始,国内二手球鞋交易领域突然开始火爆,大有成为新一轮"风口&quo ...

  9. python中一行字符串太多写不下时怎么写

    ‘123456789‘ 见此博客    https://www.cnblogs.com/wanderingzj/p/5244451.html str1=('123 '455' '789') 这样的话, ...

  10. vue实现隔行换色,下拉菜单控制隔行换色的颜色

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...