Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

298
Views
Is it possible to define an variable as base url on nuxt.js

what I trying to do is define a base url variable for my API which is able to be called everywhere on nuxt app. for example I'm trying to call an image from my API storage like bellow

<img :src="`${baseUrl}/****/****.png`">

Assuming I can define the variable, so I don't need to change every img url when the API domain changed. or I would be very thankful for introduce any better way to calling image from API storage. btw I'm using Laravel as the API.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use one of the runtimeConfig for this, publicRuntimeConfig or privateRuntimeConfig depending on your requirement

nuxt.config.js

export default {
  publicRuntimeConfig: {
    baseURL: 'https://nuxtjs.org'
  },
  privateRuntimeConfig: {
    apiSecret: 'something_private'
  }
}

Once added this variable will be available under $config across your Nuxt app like below

In templates

<template>
  <p>Our Url is: {{ $config.baseURL}}</p>
</template>

In places where you use the context (plugins, asyncData etc)

<script>
  asyncData ({ $config: { baseURL } }) {
    const posts = await fetch(`${baseURL}/posts`)
      .then(res => res.json())
  }
</script>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!