Home > Enterprise >  how to get data from backend in nuxt 3 without using composition api
how to get data from backend in nuxt 3 without using composition api

Time:09-27

I hope you are fine. I want to send a get request in nuxt3 without using composition api but I don't know how to do that. I will thank anyone who give me a piece of guidance. Thanks.

async getPosters(){
        const results = await this.$axios.get('posters')
        this.posters = results.data
    },

CodePudding user response:

Write your code as you were used too with just Options API, nothing have changed on that matter.
You can totally use Options API while using Vue3/Nuxt3. They may have some small changes but nothing too major for a simple task of querying a backend.

CodePudding user response:

It looks like this is more of an issue with trying to load Axios rather than it is with the composition API. Nuxt 3 makes Axios a redundant module.

Since Fetch is the go-to considered method of requesting data in Nuxt3, have you tried changing the method of your request? It means having to load one less module for your project, and will make it a lot easier to transition between SSR and Static in the future. If not, it might be worth using the previous version of Nuxt.

Here's the documentation: https://v3.nuxtjs.org/getting-started/data-fetching in Nuxt 3.

  • Related