Skip to content

Instantly share code, notes, and snippets.

@Borzenko

Borzenko/demo.js Secret

Created January 26, 2017 10:15
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 Borzenko/b186c6ce7e009c25528f64c8548a2cfe to your computer and use it in GitHub Desktop.
Save Borzenko/b186c6ce7e009c25528f64c8548a2cfe to your computer and use it in GitHub Desktop.
import axios from 'axios';
require('malihu-custom-scrollbar-plugin')($);
import config from '../../config';
export default {
name: 'weather',
data: () => ({
location: {},
weather: {},
cities: [],
cityName: '',
}),
mounted: async function () {
this.location = await this.getLocation();
this.location = {...this.location.data};
this.cities.push({ title: this.location.city, region: this.location.region},);
this.cities.map(async (item) => {
let weather = await this.getWeather(item);
weather = weather.data;
item.weather = weather;
return item;
});
setTimeout(() => {
$('.test').mCustomScrollbar({
axis:"x"
});
}, 0);
},
methods: {
getLocation: () => (axios.get(config.services.ipInfo.url)),
getWeather: location => {
const url = config.services.openWeatherMap.url;
const apiKey = config.services.openWeatherMap.apiKey;
return axios.get(`${url}/data/2.5/forecast/daily?q=${location.city}&appid=${apiKey}`);
},
parseWeatherData: weather => {
return weather.list.map(item => {
item.temp.avg = (item.temp.morn + item.temp.eve + item.temp.day + item.temp.night) / 4;
item.dt = item.dt * 1000;
item.date = new Date(item.dt);
item.weekDay = item.date.getDay();
item.monthDay = item.date.getDate();
return item;
});
},
addCity: function() {
this.cities.push({title: cityName});
this.cityName = '';
},
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment