这是我的代码和脚本:
<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>
我从API端点得到的响应是正确的。它显示了pic src但没有显示图像。
1条答案
按热度按时间wpx232ag1#
请添加图像源的绝对路径,我的意思是像“img/task”