添加允许获取路由Url参数
vue{ path: "/", component: Layout, redirect: "/dashboard", children: [ { path: "dashboard", // 路由路径 name: "控制台", // 路由名称 component: () => import("@/views/dashboard/index"), // 组件路径 meta: { title: "控制台", icon: "dashboard", affix: true }, props: true, // 启用参数传递 }, ], },
关键代码: props: true
捕获freelogin路由参数 隐藏组件
vue<template> <div :class="classObj" class="app-wrapper"> <div v-if="device==='mobile'&&sidebar.opened" class="drawer-bg" @click="handleClickOutside" /> <sidebar class="sidebar-container" v-if="!isSidebarHidden"/> <div class="main-container"> <div :class="{'fixed-header':fixedHeader}" v-if="!isSidebarHidden"> <navbar /> </div> <tags-View v-if="!isSidebarHidden"/> <app-main /> </div> </div> </template> <script> <template> <div :class="[classObj, {'sidebar-hidden': isSidebarHidden}]" class="app-wrapper"> <div v-if="device==='mobile'&&sidebar.opened" class="drawer-bg" @click="handleClickOutside" /> <sidebar class="sidebar-container" v-if="!isSidebarHidden"/> <div class="main-container"> <div :class="{'fixed-header':fixedHeader}" v-if="!isSidebarHidden"> <navbar /> </div> <tags-View v-if="!isSidebarHidden"/> <app-main /> </div> </div> </template> <script> import { Navbar, Sidebar, AppMain, TagsView } from './components' import ResizeMixin from './mixin/ResizeHandler' export default { name: 'Layout', components: { Navbar, Sidebar, AppMain, TagsView }, mixins: [ResizeMixin], computed: { sidebar() { return this.$store.state.app.sidebar }, device() { return this.$store.state.app.device }, fixedHeader() { return this.$store.state.settings.fixedHeader }, classObj() { return { hideSidebar: !this.sidebar.opened, openSidebar: this.sidebar.opened, withoutAnimation: this.sidebar.withoutAnimation, mobile: this.device === 'mobile' } }, // 控制侧边栏隐藏的计算属性 isSidebarHidden() { return this.$route?.query?.freelogin === '1' } }, methods: { handleClickOutside() { this.$store.dispatch('app/closeSideBar', { withoutAnimation: false }) } } } </script> <style lang="scss" scoped> @import "~@/styles/mixin.scss"; @import "~@/styles/variables.scss"; .app-wrapper { @include clearfix; position: relative; height: 100%; width: 100%; &.mobile.openSidebar{ position: fixed; top: 0; } } .drawer-bg { background: #000; opacity: 0.3; width: 100%; top: 0; height: 100%; position: absolute; z-index: 999; } .fixed-header { position: fixed; top: 0; right: 0; z-index: 9; width: calc(100% - #{$sideBarWidth}); transition: width 0.28s; } .hideSidebar .fixed-header { width: calc(100% - 54px) } .mobile .fixed-header { width: 100%; } // 侧边栏隐藏时的样式调整 .app-wrapper.sidebar-hidden .main-container { margin-left: 0 !important; // 移除左侧边距 width: 100% !important; // 主内容占满全屏 } .app-wrapper.sidebar-hidden .fixed-header { width: 100% !important; // 顶部导航占满全屏 } </style>
关键代码: this.$route?.query?.freelogin
本文作者:周得水
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!