This is my code and script:
<template>
<div >
<div >
<h1>Tasks</h1>
<ul >
<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>
My response is correct from the API endpoint. It shows pic src but not displaying an image.
CodePudding user response:
Please add an absolute path to the image src, i mean like "img/task"