最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue實(shí)現(xiàn)天氣預(yù)報(bào)功能

 更新時(shí)間:2021年08月26日 16:06:00   作者:DaftWeeknd  
這篇文章主要為大家詳細(xì)介紹了Vue實(shí)現(xiàn)天氣預(yù)報(bào)功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文為大家分享了Vue實(shí)現(xiàn)天氣預(yù)報(bào)功能的具體代碼,供大家參考,具體內(nèi)容如下

1、功能描述

在搜索框中輸入城市,下方出現(xiàn)今天及未來(lái)四天的天氣情況。搜索框下面固定了幾個(gè)城市,點(diǎn)擊可以快速查詢(xún)。

2、html代碼

 <div id="app">
        <div id="srchbar">
            <input type="text" v-model="city" @keyup.enter="srch(city)" id="ipt">
            <a @click=srch(city) id="btn">search</a>
        </div>
        <nav>
            <a href="#" @click="srch('北京')">北京</a>
            <a href="#" @click="srch('上海')">上海</a>
            <a href="#" @click="srch('廣州')">廣州</a>
            <a href="#" @click="srch('深圳')">深圳</a>
        </nav>
        <div id="res">
            <table>
                <tr>
                    <th v-for="item in forecasts">{{item.type}}</th>
                </tr>
                <tr>
                    <td v-for="item in forecasts">{{item.low}}~{{item.high}}</td>
                </tr>
                <tr>
                    <td v-for="item in forecasts">{{item.date}}</td>
                </tr>
            </table>
        </div>
</div>

3、js代碼

var app = new Vue({
        el: "#app",
        data: {
            city: "",
            forecasts: []
        },
        methods: {
            srch: function (c) {
                var that = this;
                axios.get("http://wthrcdn.etouch.cn/weather_mini?city=" + c).then(function (message) {
                    that.city = c;
                    that.forecasts = message.data.data.forecast;
                })
            }

        }
})

結(jié)果示意

總結(jié)

主要練習(xí)了v-for, v-model, v-on表達(dá)式,以及使用axios通過(guò)接口請(qǐng)求數(shù)據(jù)。

小編之前學(xué)習(xí)過(guò)程中曾將收藏了一段關(guān)于天氣預(yù)報(bào)功能的js關(guān)鍵代碼,分享給大家,一起學(xué)習(xí)。

// 請(qǐng)求地址:http://wthrcdn.etouch.cn/weather_mini
// 請(qǐng)求方法:get,
// 請(qǐng)求參數(shù):city(城市名)
// 響應(yīng)內(nèi)容:天氣信息,

// 1.點(diǎn)擊回車(chē)
// 2.查詢(xún)數(shù)據(jù)
// 3.渲染數(shù)據(jù)

var app = new Vue({
 el: '#app',
 data: {
  city: '',
  weatherList: [],
 },
 methods: {
  serchWeather: function() {
   // console.log('天氣查詢(xún)');
   // console.log(this.city)
   // 調(diào)用接口
   //保存this
   var that = this;
   axios.get('http://wthrcdn.etouch.cn/weather_mini?city=' + this.city)
    .then(function(response) {
     console.log(response.data.data.forecast)
     that.weatherList = response.data.data.forecast
    }).catch(function(err) {})
  },
  changeCity: function(city) {
          //1.改城市
     //2.查天氣
     this.city=city;
     this.serchWeather();
  }
 }
})

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

东兰县| 南京市| 河北区| 萨迦县| 平罗县| 内江市| 漳州市| 德惠市| 县级市| 多伦县| 九龙城区| 昭平县| 眉山市| 平原县| 武山县| 亚东县| 乌兰察布市| 宣威市| 上杭县| 济南市| 塔河县| 南安市| 牟定县| 常德市| 通化市| 根河市| 张掖市| 图木舒克市| 周宁县| 河源市| 礼泉县| 祁东县| 临泉县| 巴彦县| 威信县| 介休市| 军事| 酒泉市| 绥芬河市| 绥阳县| 肇庆市|