I'm learning Vue.js, and I have trouble finding anything related to this topic. I fetch the data from the API, which shows in console.log correctly, but I can't seem to return it to the template view. I am not trying to send this data to another component; I want to display it. How do you make this happen? In React, I would map the result and return the HTML. How do you do this in Vue.js? Also, I am doing this in Laravel 8.
<template>
<div>
{{ data }}
</div>
</template>
<script>
let api = location.search.replace("?", "/");
api = api.replace("=", "");
export default {
name: "Play",
data: function () {
return {
data: data
};
},
created() {
this.getQuestions();
},
methods: {
getQuestions() {
let data = [];
fetch(api)
.then(response => response.json())
.then(response => {
return (data = response.results);
})
.catch(err => console.log(err));
}
}
};
</script>