You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1013 B
51 lines
1013 B
<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>
|
|
|