zoukankan      html  css  js  c++  java
  • 小程序案例-查询天气

    /**
       * 组件的初始数据
       */
      data: {
        region:"点击选择地区",
        wd:"**",
        tq:"**",
        njd:0,
        qy:0,
        sd:0,
        fx:0,
        fs:0,
        fl:0,
        img:305
      },
      changRegion:function(e){
        var that=this;
        this.setData({
          region:e.detail.value
        })
        var str = e.detail.value;
        str = str.join(',');
        console.log(str);
        wx.request({
          url: 'https://free-api.heweather.net/s6/weather/now?', //仅为示例,并非真实的接口地址
          data: {
            location:that.data.region[1],
            key: '687a71132d6d4bfc8136011fa39dd345'
          },
          header: {
            'content-type': 'application/json' // 默认值
          },
          success: function (res) {
            var info=res.data.HeWeather6[0];
            console.log(info)
            that.setData({
              wd: info.now.tmp,
              tq: info.now.cond_txt,
              njd: info.now.vis,
              qy: info.now.pres,
              sd: info.now.hum,
              fx: info.now.wind_dir,
              fs: info.now.wind_spd,
              fl: info.now.wind_sc,
              img: info.now.cond_code,
            })
          }
        })
      },

    <view class="content">
    <!-- 区域1 地区 -->
    <picker custom-item="中国" mode="region" bindchange="changRegion">
     <view>{{region}}</view>
    </picker>
    <!-- 区域2 文本 -->
    <text>
     {{wd}}°C {{tq}}
    </text>
    <image src="/images/{{img}}.png"></image>
    
    <!-- 区域4 -->
    <view class="detail">
      <view class="bar">
        <view class="box">能见度</view>
        <view class="box">气压</view>
        <view class="box">湿度</view>
      </view>
      <view class="bar">
        <view class="box">{{njd}}%</view>
        <view class="box">{{qy}}hPa</view>
        <view class="box">{{sd}}Km</view>
      </view>
      <view class="bar">
        <view class="box">风向</view>
        <view class="box">风速</view>
        <view class="box">风力</view>
      </view>
      <view class="bar">
        <view class="box">{{fx}}</view>
        <view class="box">{{fs}}Km/H</view>
        <view class="box">{{fl}}</view>
      </view>
    </view>
    
    </view>

    css使用 flex布局

  • 相关阅读:
    MongoDB学习笔记(一:常见问题汇总)
    设计模式学习笔记(三:装饰模式)
    设计模式学习笔记(二:观察者模式)
    设计模式学习笔记(一:命令模式)
    Java基础知识笔记(七:接口、变量作用域和参数传递)
    Java基础知识笔记(六:网络程序设计)
    一周总结汇总_2016-09-25
    开涛spring3(8.1)
    开涛spring3(7.5)
    开涛spring3(7.4)
  • 原文地址:https://www.cnblogs.com/xiaozhang666/p/11382297.html
Copyright © 2011-2022 走看看