vue实现天气查询

效果如下:

 支持回车查询和点击查询,使用axios调用http://wthrcdn.etouch.cn/weather_mini接口

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){
               
               console.log(response.data.data.forecast);
               that.weatherList = response.data.data.forecast
           })
           .catch(function(err){})
        }
    },
})
View Code
原文地址:https://www.cnblogs.com/spare-ribs/p/12631428.html