Discussion icon indicating copy to clipboard operation
Discussion copied to clipboard

how to define global variables in vue.js?

Open aliuygur opened this issue 8 years ago • 4 comments

how to I define global variables such as baseUrl, isLoggedIn, ec, then i access those from any component ?

aliuygur avatar Aug 11 '15 15:08 aliuygur

Just put it inside data in the main app and use inherit: true in the child components.

swift1 avatar Aug 11 '15 19:08 swift1

Using a build tool like webpack you could define "service" modules and require or import those service modules into your component definition files. e.g configService could be an object with baseUrl, isLoggedIn properties.

fergaldoyle avatar Aug 12 '15 13:08 fergaldoyle

@fergaldoyle thank your goog idea.

aliuygur avatar Aug 13 '15 09:08 aliuygur

You could create a mixin component that has a function that outputs your value.

auzadventure avatar May 14 '17 15:05 auzadventure