日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

vue实战第一课:天气查询

發布時間:2025/3/21 vue 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 vue实战第一课:天气查询 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

查看天氣界面如下:

  • index.html如下:

  • <!DOCTYPE html>

    <html lang="en">

    ?

    <head>

    <meta charset="UTF-8" />

    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <title>天氣預報</title>

    <link rel="stylesheet" href="css/reset.css" />

    <link rel="stylesheet" href="css/index.css" />

    </head>

    ?

    <body>

    <div class="wrap" id="app">

    <div class="search_form">

    <div class="logo"><img src="img/logo.png" alt="logo" /></div>

    <div class="form_group">

    <input type="text" class="input_txt" placeholder="請輸入查詢的天氣"

    v-model="city"

    @keyup.enter="queryWeather" />

    <button class="input_sub" @click="searchWeather()">

    搜 索

    </button>

    </div>

    <div class="hotkey">

    <a href="javascript:;"

    v-for="city in hotCitys"

    @click="clickSearch(city)">{{ city }}</a>

    </div>

    </div>

    <div class="weather_list">

    <li v-for="item in weatherList">

    <div class="info_type">

    <span class="iconfont">{{ item.type }}</span>

    </div>

    <div class="info_temp">

    <b>{{ item.low }}</b>

    ~

    <b>{{ item.high }}</b>

    </div>

    <div class="info_date">

    <span class="info_date">{{ item.date }}</span>

    </div>

    </li>

    </div>

    </div>

    ?

    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>

    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>

    <script src="js/main.js"></script>

    </body>

    ?

    </html>

    ?

    2. main.js如下:

    var app = new Vue({

    el: "#app",

    data: {

    city: "北京",

    weatherList: [],

    hotCitys: ["北京", "上海", "廣州", "深圳"]

    },

    methods: {

    searchWeather: function() {

    var that = this;

    axios

    .get(`http://wthrcdn.etouch.cn/weather_mini?city=${this.city}`)

    .then(response => (that.weatherList = response.data.data.forecast));

    },

    clickSearch:function(city) {

    this.city = city;

    this.searchWeather();

    }

    }

    });

    ?

    總結

    以上是生活随笔為你收集整理的vue实战第一课:天气查询的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。