鱼C论坛

 找回密码
 立即注册
查看: 4077|回复: 5

[作品展示] 基于vue和axios的天气查询

[复制链接]
发表于 2019-11-24 02:24:53 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 我不是他i 于 2019-11-24 02:27 编辑

游客,如果您要查看本帖隐藏内容请回复
基于vue.js和axios.js制作的天气查询,是个学习vue.js非常时候拿来练手的小项目
这是html的代码
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7.     <title>天气查询</title>
  8.     <link rel="stylesheet" href="./style.css">
  9. </head>
  10. <body>
  11.     <div id="app" class="wrap">
  12.         <div class="search_form">
  13.             <div class="logo">天气查询</div>
  14.             <div class="form_group">
  15.                 <input type="text" @keyup.enter="searchweather" class="input_text" placeholder="请输入查询的天气" v-model="city">
  16.                 <button class="input_sub">
  17.                     搜索
  18.                 </button>
  19.             </div>
  20.             <div class="hotkey">
  21.                 <a href="javascript:;">北京</a>
  22.                 <a href="javascript:;">上海</a>
  23.                 <a href="javascript:;">广州</a>
  24.                 <a href="javascript:;">深圳</a>           
  25.             </div>
  26.         </div>
  27.         <ul class="weather_list">
  28.             <li v-for="item in weatherList">
  29.                 <div class="info_type"><span class="iconfont">{{ item.type }}</span></div>
  30.                 <div class="info_temp">
  31.                     <b>{{ item.low }}</b>
  32.                     ~
  33.                     <b>{{ item.high }}</b>
  34.                 </div>
  35.                 <div class="info_date"><span>{{ item.date }}</span></div>
  36.             </li>
  37.         </ul>
  38.     </div>

  39.     <script src="https://cdn.jsdelivr.net/npm/vue"></script>
  40.     <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
  41.     <script src="./main.js"></script>
  42. </body>
  43. </html>
复制代码

注意:这里的vue和axios的引用是没有先后关系的
这里是css的代码
  1. /*style.css*/
  2. *{
  3.     padding: 0px;
  4.     margin: 0px;
  5. }
  6. #app {
  7.     text-align: center;
  8.     margin: 100px 0px;
  9. }
  10. .logo {
  11.     font-size: 20px;
  12.     font-family: "宋体";
  13. }
  14. .form_group {
  15.     margin-top: 10px;
  16. }
  17. .input_text {
  18.     height: 30px;
  19.     width: 500px;
  20. }
  21. .input_sub {
  22.     height: 34px;
  23.     border: none;
  24.     width: 50px;
  25.     margin-left: -5px;
  26.     vertical-align: middle;
  27.     background-color: skyblue;
  28. }
  29. .hotkey>a {
  30.     color: black;
  31.     text-decoration: none;
  32. }
  33. .hotkey {
  34.     margin-top: 10px;
  35.     margin-left: -400px;
  36. }
  37. .weather_list>li {
  38.     height: 100px;
  39.     display: inline-block;
  40.     list-style: none;
  41.     border-right: 3px salmon solid;
  42.     margin-right: 30px;
  43.     padding-right: 30px;
  44.     margin-top: 10px;
  45.     line-height: 35px;
  46. }
复制代码

这里是js的代码了
  1. //main.js
  2. var app = new Vue({
  3.     el:"#app",
  4.     data:{
  5.         city:"",
  6.         weatherList:[],
  7.     },
  8.     methods: {
  9.         searchweather:function(){
  10.             // console.log("查询天气");
  11.             // console.log(this.city);
  12.             var that = this;
  13.             axios.get("http://wthrcdn.etouch.cn/weather_mini?city="+this.city).then(function(response){
  14.                 console.log(response.data.data.forecast);
  15.                 that.weatherList = response.data.data.forecast;
  16.             })
  17.         }
  18.     },
  19. })
复制代码

主要就是使用axios和vue的相互结合啦
QQ截图20191124021441.png
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-12-18 21:56:38 | 显示全部楼层
666666
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-7-7 15:31:46 | 显示全部楼层
np
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-7-7 17:12:21 | 显示全部楼层
学习一下
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-11-5 14:05:53 | 显示全部楼层
恢复
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-11-5 19:35:02 | 显示全部楼层
不错
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-19 19:53

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表