Skip to content

Instantly share code, notes, and snippets.

@Taifunov
Created January 30, 2020 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Taifunov/16f6208b35d022ed163886fb9cb8f661 to your computer and use it in GitHub Desktop.
Save Taifunov/16f6208b35d022ed163886fb9cb8f661 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://unpkg.com/axios@0.19.2/dist/axios.min.js"></script>
<title>Document</title>
</head>
<body>
<div id="vue">
<button type="button" @click="getHashTags">Грузи Теги</button>
<ul>
<li v-for="hashtag in hashtags">{{hashtag}}</li>
</ul>
<button type="button" @click="getCities">Грузи Города</button>
<ul>
<li v-for="city in cities">{{city.region}}, {{city.city}}</li>
</ul>
<button type="button" @click="getWeather">Грузи Погоду</button>
<ul>
<li v-for="weather in weatherArray">{{weather.name}} : {{weather.temp}}</li>
</ul>
</div>
<script>
var app = new Vue({
el: '#vue',
data: {
hashtags:[],
cities: [],
weatherArray:[],
url:{
hashtags: 'https://dka-develop.ru/api?type=hashtag',
cities: 'https://dka-develop.ru/api?type=city',
weather: 'https://cors-anywhere.herokuapp.com/https://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=86e52e395a4259b27e606dc2daa74ed5'
}
},
created: function(){
console.log("LINK:" + this.url.weather);
},
methods:{
getHashTags(){
axios.get(this.url.hashtags)
.then((response) => {
console.log(response.data);
this.hashtags = response.data;
})
},
getCities(){
axios.get(this.url.cities)
.then((response) => {
console.log(response.data);
this.cities = response.data;
})
},
getWeather(){
axios.get(this.url.weather)
.then((response) => {
console.log('WEATHER RESPONSE: ' + JSON.stringify(response.data));
this.weatherArray = response.data;
})
.catch(error => console.log(error));
},
}
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment