You are browsing Nuxt 2 docs. Go to Nuxt 3 docs, or learn more about Nuxt 2 Long Term Support.

Anonymous Middleware

Using anonymous middleware to show the analytics of how many times a user visits a page.


In this example:

pages/anonymous-middleware.vue contains a middleware function which uses the store to call the increment mutation with results from the store displayed on the page.

store/analytics.js sets the pageVisits to 0 and increments the visits every time the increment function is called.

Loading Sandbox...