vue2.x elementui 固定顶部、左侧菜单与面包屑,自适应 iframe 页面布局

vue elementui 固定顶部、左侧菜单与面包屑,自适应 iframe 页面布局

疑问点:iframe无法高度100%,如果写了100%就会有滚动条,所以只写了99.5%

【效果图】

路由示例

javascript 复制代码
const routes = [
    {
        title: 'Index',
        path: '/',
        name: "Index",
        component: () => import('@/views/Index.vue'),
    },
    {
        title: 'TEST',
        path: '/TEST', // 使用内部页面时,路径为 "#/TEST"
        name: "TEST",
        component: () => import('@/views/TEST.vue'),
    },
]

页面完整代码

javascript 复制代码
<template>
  <div class="container">
    <div class="top">
      <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" @select="handleSelect">
        <el-menu-item index="1">Home</el-menu-item>
        <el-submenu index="2">
          <template slot="title">Options</template>
          <el-menu-item index="2-1">Option1</el-menu-item>
          <el-menu-item index="2-2">Option2</el-menu-item>
          <el-submenu index="2-4">
            <template slot="title">Option3</template>
            <el-menu-item index="2-4-1">Option3-1</el-menu-item>
            <el-menu-item index="2-4-2">Option3-2</el-menu-item>
          </el-submenu>
        </el-submenu>
        <el-menu-item index="3" disabled>Msg</el-menu-item>
        <el-menu-item index="4"><a href="https://www.ele.me" target="_blank">Order</a></el-menu-item>
      </el-menu>
    </div>
    <div class="wrap">
      <div class="l">
        <p style="margin-top: 32px;">aside-bar</p>
      </div>
      <div class="r">
        <div class="bread-wrap">
          <el-breadcrumb separator="/">
            <el-breadcrumb-item>首页</el-breadcrumb-item>
            <el-breadcrumb-item><a href="/">活动管理</a></el-breadcrumb-item>
            <el-breadcrumb-item>活动列表</el-breadcrumb-item>
            <el-breadcrumb-item>活动详情</el-breadcrumb-item>
          </el-breadcrumb>
        </div>
        <div class="iframe-wrap">
          <iframe :src="iframeUrl" width="100%" height="99.5%" frameborder="0"></iframe>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      activeIndex: '1',
      // iframeUrl: '#/TEST',  // 关键点:使用内部页面的话,要按这样写
      iframeUrl: 'https://www.baidu.com',
    }
  },
  methods: {
    handleSelect(key, keyPath) {
      console.log(key, keyPath);
    }
  }
}
</script>

<style scoped lang="less">
.container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  color: #fff;

  &>.top {
    height: 48px;
    background: #212121;
  }

  &>.wrap {
    flex: 1;
    display: flex;
    height: 0;

    &>.l {
      width: 200px;
      background: #212121;
    }

    &>.r {
      overflow-y: hidden;
      display: flex;
      flex-direction: column;
      flex: 1;
      width: 0;
      background: #fff;

      .bread-wrap {
        display: flex;
        align-items: center;
        height: 48px;
      }

      .iframe-wrap {
        overflow-y: auto;
        flex: 1;
        height: 0;
      }
    }
  }
}

.el-menu {
  height: 100%;
  background: transparent;
}

/deep/.el-menu--horizontal>.el-submenu .el-submenu__title,
.el-menu--horizontal>.el-menu-item,
.el-menu--horizontal>.el-submenu .el-submenu__title {
  height: 48px;
  line-height: 48px;
  color: #ccc;
}

.el-menu--horizontal>.el-menu-item.is-active {
  color: #fff;
}

.el-menu.el-menu--horizontal {
  border-bottom: solid 1px #000;
}
</style>
相关推荐
一份执念7 分钟前
uni-app项目 (vue+vite + uni-UI)中引入umd格式JS文件,微信小程序中导入报错处理方案
前端·uni-app·echarts
ClouGence17 分钟前
2026 年自动化测试工具选型指南:8 款主流工具对比
前端·测试
lichenyang4531 小时前
为什么需要双线程通信、JavaScriptProxy 和 runJavaScript 分别干什么
前端
以和为贵1 小时前
前端也能搞懂 RAG:用 JS 手写一条最小检索增强链路
前端·人工智能·面试
风止何安啊1 小时前
网课倍速痛点解决:一套前端代码实现自由控速播放器
前端·javascript·node.js
牧艺1 小时前
用 Next.js + React Three Fiber 打造 3D 快递仓储可视化
前端·three.js
锋行天下2 小时前
如何用Vite实现Vue组件的按需打包和远程加载
前端·vue.js·前端框架
光影少年2 小时前
原生DOM操作在React 中的注意事项
前端·javascript·react.js
禅思院5 小时前
前端部署“三层漏斗”完全指南:从CI/CD到自动回滚的工程化实战【开题】
前端·架构·前端框架
快乐肚皮5 小时前
深入理解Loop Engineering
前端·后端