我不知道我出了什么問題,也不知道為什么這不起作用,我只是想讓隨機(jī)狗的照片 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) } } } };
您必須調(diào)用 getData
函數(shù)。一種可能的解決方案是,您可以在 mounted
生命周期掛鉤中調(diào)用 getData
函數(shù)。這是一個(gè) vue 游樂場 鏈接
sssccc![]()