簡體   English   中英

如何在 Nuxt.js 中僅設置中間件特定頁面

[英]How to set middleware only specific page in Nuxt.js

在我的 Nuxt 應用程序的indexabout-uscontact-us頁面中,我看到了這個錯誤:

GET http://127.0.0.1:8000/api/auth/user 401 (Unauthorized)

我安裝了auth ,並使用 Laravel API 中的 JWT。 我希望它僅用於dashboarddashboard/userdashboard/post頁面。

GET http://127.0.0.1:8000/api/auth/user

通過設置middleware屬性,頁面組件可以擁有自己的中間件。

Nuxt 文檔展示了這個匿名中間件的例子:

<template>
  <h1>Secret page</h1>
</template>

<script>
  export default {
    middleware({ store, redirect }) {
      // If the user is not authenticated
      if (!store.state.authenticated) {
        return redirect('/login')
      }
    }
  }
</script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM