찾다

 >  Q&A  >  본문

Vue.js에 대한 API 풀 생성

나에게 무슨 문제가 있는지, 왜 이것이 작동하지 않는지 모르겠습니다. 임의의 개 사진 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)
      }
    }
  }
};

P粉111641966P粉111641966304일 전586

모든 응답(1)나는 대답할 것이다

  • P粉300541798

    P粉3005417982024-04-04 00:08:51

    getData 函数。一种可能的解决方案是,您可以在 mounted 生命周期挂钩中调用 getData 함수를 호출해야 합니다. 이곳은 Vue 놀이터입니다 link

    으아아아

    회신하다
    0
  • 취소회신하다