Skip to content Skip to sidebar Skip to footer

I Am Using Vue Js And Python Flask As My Backend. I Want To Have Some Local Variable Set. How Can It Be Done?

My Vue js file. Here I am using two urls from localhost. I want to make a configuration file such that if I make changes in config file, I will be able to get the same changes. <

Solution 1:

As I mentioned in comment - you can create some external object, something like this, let's call it config.js

export default {

    config: {
      url: 'myurl'
    }   

}

Then import it in your component file

importConfigFilefrom'../config'

Then in your data you can use it like this

data() {
  return {
   url: ConfigFile.config.url
  }
}

And then you can use url it in your template.

<p>{{ url }}</p>

Solution 2:

Since you use flask as a backend, you can just include config.js as a script before you include the vue scripts

const URL = http://127.0.0.1:5000/

Inside your vue files, you can then have access to the URL variable

Post a Comment for "I Am Using Vue Js And Python Flask As My Backend. I Want To Have Some Local Variable Set. How Can It Be Done?"