Vue搭配axious简单项目 天气预报

main.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Documen</title>
</head>

<body>
    <div id="app">
        <input type="text" placeholder="请输入查询" @keyup.enter="searchWeather" v-model="city">
        <button @click="searchWeather">搜索</button>
        <ul>
            <li v-for="item in weatherList">
                <span>{{item.type}}</span>
                <div>
                    <b>{{item.low}}</b>
                    ~
                    <b>{{item.high}}</b>
                </div>
                <div><span>{{item.date}}</span></div>
            </li>
        </ul>
    </div>
    <!-- 开发环境版本,包含了有帮助的命令行警告 -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <!-- 导入axios -->
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <!-- 导入自己的js  -->
    <script src="./js/main.js"></script>
</body>

</html>

main.js

var app = new Vue({
    el: ‘#app‘,
    data: {
        city:"",
        weatherList:[],
    },
    methods:{
        searchWeather:function(){
            var that=this;
            axios.get(‘http://wthrcdn.etouch.cn/weather_mini?city=‘+this.city)
            .then(function(response){
                    that.weatherList=response.data.data.forecast;
                    console.log(response.data.data.forecast);
                }
            )
            .catch(function(err){
                    console.log("未知城市")
                }
            )
        }
    }
})

Vue搭配axious简单项目 天气预报

上一篇:React-Antd4的Form表单校验


下一篇:ORACLE的DDL日志 推送到Kafka,并接入Flink,进行统计