<template>
<article class="message is-warning">
<div class="message-header">
<span>Code Examples</span>
</div>
<div class="message-body">
<span v-html="fetchedExamples.data.example"></span>
<span>{{fetchedExamples.data.author}}</span>
</div>
</article>
</template>
<script>
export default {
data(){
return {
fetchedExamples: [],
contentUrl: "https://apiurl.tld/"
};
},
mounted() {
this.getExamples(this.contentUrl, "examples");
},
methods: {
async getExamples(url, collection) {
try {
let response = await fetch(url + collection+"/"+Math.ceil(Math.random()*6));
this.fetchedExamples = await response.json();
} catch (error) {
console.log(error);
}
}
}
};
</script>
I am attempting to randomly retrieve examples from a specific project's API. However, whenever I run this code, I encounter the following error :
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'quote').
I have tested multiple solutions without success, and now I'm seeking assistance in identifying what might be causing this code to malfunction.
Your help would be greatly appreciated.