<template>
  <img alt="Vue logo" src="./assets/logo.png">
  <!-- <div>{{ answer }}</div> -->
  <br>
  <button @click="getAnswer">GET</button>
  <div>
    <h1>{{ answer.answer }}</h1>
    <div v-if="answer.image">
      <img :src="answer.image" alt="Random GIF">
    </div>
  </div>
</template>

<script>
//npm install axios
import axios from "axios"

export default {
  name: 'App',
  data(){
    return {
      answer: {},
    }
  },
  methods: {
    async getAnswer() { //načteme data z webu
      try { // try vyzkouší získání dat
        const {data} = await axios.get("https://yesno.wtf/api");
        this.answer = data;
      } catch (error) { // vyhodí chybu
        console.error("Nastala chyba",error);
      }
    }
  },
  beforeMount() {
    this.getAnswer();

  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
