I don't know what's wrong with me or why this isn't working, I just want the random dog photo api to work but it's not working. See the code below.
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) } } } };
P粉3005417982024-04-04 00:08:51
You must call the getData
function. One possible solution is that you can call the getData
function in the mounted
lifecycle hook. This is a vue playground Link
sssccc