我正在尝试构建一个简单的应用程序,以便像这样从公共api获取数据。
<template>
<div>
<v-card v-for="fact in facts" :key="fact._id" :id="fact._id">
<v-card-title class="headline">
{{fact.text}}
</v-card-title>
</v-card>
</div>
</template>
<script>
import axios from 'axios';
export default {
data(){
return{
facts:[]
}
},
async created(){
const config = {
headers: {
'Accept': 'application/json'
}
}
try{
const res = await axios.get('https://cat-fact.herokuapp.com/facts', config);
this.facts = res.data;
}catch (err){
console.log(err)
}
}
}
</script>
[当我执行console.log(this.facts)
时,它将返回cli
中的数据,但不在网站上。它不会遍历所有项目。我在这里错了吗?