Issue
I have axios module in my Nuxt.js project.
I also set up my baseUrl (for API) in localhost:4040/api
while my client is running on port 3000.
When I fetch image data in the API, it returns a relative path to the api server which is like '/upload/1.png'
{
"src":"/upload/1.png"
}
So, I need to get the axios baseUrl and concat it with it to make full path to the image.
Is there any way to do it other than hardcoding it?
Solution
If in nuxt.config.js you defined:
axios: {
baseURL:"localhost:4040/api/"
}
All you need to do for the image is to point to it as follows:
:src="`${$axios.defaults.baseURL}upload/1.png`"
Answered By - Billal Begueradj Answer Checked By - Willingham (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.