22、什么是中间件和权限拦截中间件实操

新建中间件

middleware\auth.js

javascript 复制代码
// 定义权限判断中间件,中间件的第一个参数是context
export default ({store, redirect}) => {
    console.log("中间件被调用")
    // if (!store || !store.state.userinfo) {
    //     redirect("/")
    // }
}

页面使用中间件

pages\users\index.vue

javascript 复制代码
<template>
    <div>
        用户首页
    </div>
</template>

<script>
export default {
    middleware: "auth"
};
</script>

<style lang="scss" scoped>

</style>

布局使用中间件

layouts\blog\index.vue

javascript 复制代码
<template>
    <div>
        <div>测试标题</div>
        <nuxt></nuxt>
    </div>
</template>>

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

<style>

</style>

全局使用中间件

nuxt.config.js

javascript 复制代码
export default {
  router: {
    middleware: "auth"
  }
}
相关推荐
hello 早上好9 小时前
消息顺序、消息重复问题
java·中间件
is08152 天前
STM32 USB 设备中间件 tinyusb
stm32·嵌入式硬件·中间件
头发那是一根不剩了2 天前
信创缓存中间件TongRDS(Redis平替)安装、接入SpringBoot全流程
redis·缓存·中间件·tongrds
m0_659394002 天前
常见的中间件漏洞
中间件
在未来等你6 天前
RabbitMQ面试精讲 Day 5:Virtual Host与权限控制
中间件·面试·消息队列·rabbitmq
Whoisshutiao7 天前
网安-中间件-Redis未授权访问漏洞
中间件
半新半旧9 天前
FastAPI中间件
中间件·fastapi
努力找工作的OMArmy10 天前
分布式数据库中间件ShardingSphere
数据库·分布式·中间件
枷锁—sha13 天前
中间件安全攻防全解:从Tomcat到Weblogic反序列化漏洞介绍
安全·web安全·网络安全·中间件·tomcat