vuejs小例子之天气查询

2021-09-08 23:12

阅读:673

标签:var   深圳   输入框   点击事件   ima   -o   输入   npm   城市   看一个例子: 查询 北京 武汉 上海 深圳 {{item.type}} {{item.low}} {{item.high}} {{item.date}} var vue = new Vue({ el: "#app", data: { city: ‘‘, weathers: [], }, methods: { getWeathers: function () { var that = this axios.get(‘http://wthrcdn.etouch.cn/weather_mini?city=‘ + this.city) .then(function (response) { that.weathers = response.data.data.forecast; }, function (err) { }) }, changeCity: function (city) { this.city = city; this.getWeathers(); }, }, }) 效果: 在输入框中输入城市,例如武汉,回车或者点击按钮查询: 会显示相关信息。 点击下面的四个城市: 也会显示相关信息。 说明:使用v-model,v-on点击事件,v-on回车事件,v-for遍历数据,axios发送请求。vuejs小例子之天气查询标签:var   深圳   输入框   点击事件   ima   -o   输入   npm   城市   原文地址:https://www.cnblogs.com/xiximayou/p/12325492.html


评论


亲,登录后才可以留言!