簡體   English   中英

Vue Nuxt Auth 使用類組件為每個路由啟用身份驗證中間件

[英]Vue Nuxt Auth enable auth middleware per route using Class Components

如何使用類組件為每個路由啟用身份驗證中間件?

什么是等效的:

<script>
  export default {
    middleware: 'auth'
  }
</script>

這不起作用:

<script>
  import { Vue, Component } from 'nuxt-property-decorator'

  @Component
  export default class Profile extends Vue {
    middleware = 'auth'
  }
</script>

您需要將其添加為Component裝飾器中的參數。


<script lang="ts">
import { Component, Vue } from 'nuxt-property-decorator';

@Component({
  middleware: ['auth']
})
export default class Profile extends Vue {
  name = 'some data'
}
</script>

您最初所做的只會創建一個數據屬性。 除了 Vue 選項(如data computed methodshooks之外,要添加特定於組件的選項,您必須將其作為參數傳遞給@Component裝飾器

在此處閱讀更多相關信息

暫無
暫無

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

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