middleware 属性

  • 类型: StringArray
    • 数组元素类型: String在应用中的特定页面设置中间件

例子:

pages/secret.vue

  1. <template>
  2. <h1>Secret page</h1>
  3. </template>
  4. <script>
  5. export default {
  6. middleware: 'authenticated'
  7. }
  8. </script>

middleware/authenticated.js

  1. export default function ({ store, redirect }) {
  2. // If the user is not authenticated
  3. if (!store.state.authenticated) {
  4. return redirect('/login')
  5. }
  6. }

想了解更多关于使用中间件的信息,请移步 中间件指引