cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              div#app

  header: h1 {{ appTitle }}
  
  display(v-bind:res="weatherRes")
  
  actions(v-bind:location="cityName" @search="searchcity")

            
          
!
            
              // FONTS
@import url('https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300,700');
$main-font: 'Open Sans Condensed', sans-serif;

// COLORS
$white: #fff;
$black: #000;
$palette: #96A8BE, #738BA8, #506E92, #3F6083, #344F70;


// GENERAL
*, *::before, *::after{
  box-sizing: border-box;
}
body{
  font-family: $main-font;
  font-size: 16px;
  font-weight: 300;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: rgba(nth($palette, 1), .40);
}
h1,h2,h3,h4,h5,h6{
  font-weight: normal;
}


// APP STYLES
#app{
  width: 270px;
  margin: 3rem 0;
  background: nth($palette, 3);
  box-shadow: 0 15px 10px -10px rgba(nth($palette, 5), .75);
  overflow: hidden;
  h1{
    margin: 0;
    padding: .3rem 1rem;
    font-size: .75em;
    font-weight: bold;
    text-align: center;
    color: nth($palette, 4);
    background: rgba($white, .2);
  }
}
.display{
  text-align: center;
  color: $white;
  h2{
    margin: 2rem 1rem .5rem;
  }
  h5{
    position: relative;
    margin: .7rem 1rem 4rem;
    font-size: .85em;
    color: nth($palette, 1);
    &::after{
      content: '';
      position: absolute;
      bottom: -1.5rem;
      left: 50%;
      transform: translateX(-50%);
      width: 3rem;
      height: 1px;
      background: rgba($white, .65);
    }
  }
  .temp{
    padding: 0 1rem;
    font-size: 2em;
  }
  img{
    width: auto;
    height: 128px;
    display: inline-block;
  }
  .text{
    margin: 0 0 1.5rem;
    padding: 0 1rem;
    text-transform: uppercase;
    color: $white;
  }
}
.actions{
  position: relative;
  margin-top: 3rem;
  .togglSearch{
    height: 35px;
    line-height: 35px;
    padding: 0 1rem;
    font-family: $main-font;
    text-align: center;
    color: rgba(nth($palette, 1), .6);
    background: nth($palette, 4);
    transform: translateY(0);
    transition: color .4s, transform .4s;
    cursor: pointer;
    &.active{
      transform: translateY(-100%);
    }
    &:hover, &:focus{
      color: nth($palette, 1);
    }
  }
  .panel{
    position: absolute;
    bottom: 0;
    left: 0;
    display: flex;
    width: 100%;
    background: nth($palette, 5);
    transform: translateY(100%);
    transition: transform .4s;
    &.active{
      transform: translateY(0);
    }
    input, button{
      height: 35px;
      line-height: 35px;
      padding: 0 1rem;
      font-family: $main-font;
      outline: none;
      background: transparent;
      border: none;
      transition: color .4s;
      color: rgba(nth($palette, 1), .4);
      &:hover, &:focus{
        color: nth($palette, 1);
      }
    }
    input{
      flex-grow: 2;
    }
    button{
      border-left: 1px solid rgba(nth($palette, 1), .4);
      cursor: pointer;
      i{
        vertical-align: middle;
      }
    }
  }
}
            
          
!
            
              /**
 * This pen uses OpenWeatherMap weather API
 * https://openweathermap.org/
 */



/*******************************************
 * GLOBAL COMPONENTS
 *******************************************/

// DISPLAY
Vue.component('display', { 
  props: ['res'],
  template: `
    <section class="display">
      <h2>{{ res.name }}, {{ res.sys.country }}</h2>
      <h5>
        <span>Lat:</span> {{ res.coord.lat }}
        <span>Lon: {{ res.coord.lon }}</span>
      </h5>
      <div class="condition">
        <div class="temp">{{ temperature }}°C</div>
        <img v-bind:src="'https://openweathermap.org/themes/openweathermap/assets/vendor/owm/img/widgets/' + res.weather[0].icon + '.png'" 
               v-bind:alt="'Weather in ' + res.name" 
               width="128" height="128">
        <p class="text">{{ res.weather[0].description }}</p>
      </div>
    </section>
   `,
   computed: {
    temperature(){
      //Remove decimals on temperature value
      var temp = this.res.main.temp,
          noDecimals = temp.toFixed();

      return noDecimals;
    }
  }
});

// ACTIONS
Vue.component('actions', {
  props: ['location'],
  data(){
    return{
      isSearching: false  
    }
  },
  template: `
  <section class="actions">
    <div class="togglSearch" v-bind:class="{'active': isSearching}" @click="isSearching = ! isSearching">
      <span v-if="!isSearching">Search</span>
      <span v-else>Close</span>
    </div>
    <div v-bind:class="{'active': isSearching}" class="panel"> 
      <input type="text" v-model="location">
      <button @click="search"><i class="material-icons">search</i></button> 
    </div>
  </section>
`,
 methods: {
   search(){
     this.$emit('search', this.location);
     this.isSearching = false;
   }
 }
});



/*******************************************
 * ROOT COMPONENT
 *******************************************/
var app = new Vue({
  el: '#app',
  data: {
    appTitle: 'Vue Weather App',
    dataApi: 'aae97860de78632108ecc73036d6d17c',
    cityName: 'milano',
    lang: 'en',
    weatherRes: null
  },
  
  // GET DATA WHEN MOUNTED
  mounted(){
    this.performAJAX();
  },
  
  // METHODS
  methods: {
    // SEARCH A NEW CITY
    searchcity(city){
      this.cityName = city;
      var ctx = this;
      ctx.performAJAX();
    },
    
    // GET WEATHER DATA
    performAJAX(){
      var ctx = this;
    
      axios.get('https://api.openweathermap.org/data/2.5/weather?q=' + 
                ctx.cityName + '&units=metric&lang=' + 
                ctx.lang + '&APPID=' + ctx.dataApi )
      .then(function (response) { 
        ctx.weatherRes = response.data;
      })
      .catch(function (error) {
        console.log(error);
      });
    }
  }
});
            
          
!
999px
Loading ..................

Console