我不知道我出了什么问题,也不知道为什么这不起作用,我只是想让随机狗的照片 api 工作,但它不起作用。请参阅下面的代码。
export default {
data() {
return {
posts: [],
};
},
methods: {
async getData() {
try {
let response = await fetch ("https://dog.ceo/api/breeds/image/random");
this.posts = await response.json();
} catch (error){
console.log(error)
}
}
}
}; Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
您必须调用
getData函数。一种可能的解决方案是,您可以在mounted生命周期挂钩中调用getData函数。这是一个 vue 游乐场 链接