Reputation: 2897
I want to call a component only on our staging server but not on my local machine:
<save-drafts-timer v-if="!environment === 'development'" />
...
data () {
return {
environment: process.env.NODE_ENV
}
}
By doing this, will this component be always (and only) called on staging server? If not, is there some reliable way to do that?
Upvotes: 0
Views: 481
Reputation: 3614
I don't know much about your project, but process.env.NODE_ENV
is a server side environment variable, and Vue is a client side application, so it will not have access to that.
You would have to pass that environment variable to your client somehow. If you are using webpack
, you could use the DefinePlugin
feature:
https://webpack.js.org/plugins/define-plugin/
This will allow you to define a global variable which you could then access inside of Vue.
Upvotes: 1