[英]How to set middleware only specific page in Nuxt.js
在我的 Nuxt 應用程序的index
、 about-us
和contact-us
頁面中,我看到了這個錯誤:
GET http://127.0.0.1:8000/api/auth/user 401 (Unauthorized)
我安裝了auth
,並使用 Laravel API 中的 JWT。 我希望它僅用於dashboard
、 dashboard/user
和dashboard/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.