Below is the code and script that I have:
<template>
<div class="tasks_container">
<div class="tasks_content">
<h1>Tasks</h1>
<ul class="tasks_list">
<li v-for="task in tasks" :key="task.id">
<h2>{{ task.name }}</h2>
<img :src="task.pic" alt="No Image" title="Order Now" />
<p></p>
<button>
</button>
<button>Delete</button>
</li>
</ul>
</div>
</div>
</template>
<script>
export default {
data() {
return {
// tasks
tasks: ['']
}
},
methods: {
async getData() {
try {
// fetch tasks
const response = await this.$http.get('http://localhost:8000/read_retrieve/');
// set the data returned as tasks
this.tasks = (response.data);
} catch (error) {
// log the error
console.log(error);
}
},
},
created() {
// Fetch tasks on page load
this.getData();
}
}
</script>
The API endpoint responds correctly, but there seems to be an issue with displaying the image despite setting the src attribute.