What object are you trying to access? You already have access to all variables, for example
this.$store
this.$route
// etc
What about "isDev"? I'd like to access that and there seems no way to do that but from the page's, asyncData block.
Answering this myself. You can access an environmental variable with process.env.NODE_ENV
in a component.
Hi, how can access in script section? I tried "console.log($route.name)", but got error: Cannot read property 'middleware' of undefined.
@nurdus show some code and specify what you mean by script section.
<script>
// imports ...
console.log(this.$route.name) // doesn't work, I think it doesn't have to work
export default {
data () {
console.log(this.$route.name) //work
}
}
</script>
@nurdus you can't access anything regarding the route outside the export, Vue may not even be initialized there AFAIK. Why would you need to do that anyway? Maybe you need a different approach for what you're trying to achive.
I've tried testing, it was my mistake :) Thanks.
According to this doc, isDev
is available on client and server.
https://nuxtjs.org/api/context
How do you access it on client?
@blowsie have you tried process.isDev
or process.env.isDev
?
Quote from @manniL via discord.
So, the context object is available in the
asyncData
andfetch
functions (as parameter)
You also can access it innuxtServerInit
And in plugins as well
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
What about "isDev"? I'd like to access that and there seems no way to do that but from the page's, asyncData block.
Answering this myself. You can access an environmental variable with
process.env.NODE_ENV
in a component.