Home > Blockchain >  I'm having trouble with axios get and post requests in real host
I'm having trouble with axios get and post requests in real host

Time:09-24

When I'm on the local server localhost:8080 in vue project everything is great, but when I deploy the project to my real host I get the problem

mounted(){
        axios.get('http://localhost/online-store/src/database_api/Admin/recent_product.php')
        .then((res) => {
            this.products= res.data
            console.log(res.data)
        })
    },

CodePudding user response:

You need to replace your local url

axios.get('http://localhost/online-store/src/database_api/Admin/recent_product.php')

with public.

CodePudding user response:

configure your axios in main.js (entry point )

axios.create({
    baseURL: process.env.VUE_APP_BASE_URL
})

Then directly call api ..it will append base url based on your env parameter

 axios('/online-store/src/database_api/Admin/recent_product.php')

Note : Don't forget to add .env as per environment

  • Related