Create an API pull for Vue.js
P粉111641966
P粉111641966 2024-04-03 16:12:29
0
1
482

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粉111641966
P粉111641966

reply all(1)
P粉300541798

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template