[Vuejs]-$nuxt is not defined when using $nuxt.route in computed

3👍

$nuxt, precisely window.$nuxt is only available on client-side and should only be used as escape hatch.

You can access the route object via this.$route instead when using the Options API.

computed: {
    updateActiveRoute() {
        return this.$route.params.name ? this.$route.params.name : 'Hello'
    }
},

watch: {
    updateActiveRoute(newVal) {
        this.activeRoute = newVal
    }
}
👤manniL

0👍

Use this.$nuxt

Only within the template you can access variables without this.

👤Saa

Leave a comment