Vue3集成Element-Plus快速搭建管理系统的页面框架(小白版)

一、搭建后端基本框架

前情提要:本人在idea上搭建的vue3框架

出现语法提示安装插件:

在views文件夹下新建Manager.vue文件,即全局的父级文件,随后:

在index.js内增添配置:

children: [
  {path: '/home',   component: import('../views/About.vue'),},
]
},

在Manager.vue文件内增添:

<template>
  <div>


    这是父组件

  <RouterView />
    </div>



</template>


<script setup>


</script>

 

 验证一下:

成功!!!

继续修改一下配置:

children: [
  {path: 'home',   component: import('../views/Home.vue'),},
]
},

验证一下:

成功!!! 

这说明父组件嵌套子组件成功,需要路由来连接

二、配置固定区域

大家根据自己的需求更改代码即可,下边是示例:

<template>
  <div>
  <!-- 头部区域开始 -->
    <div style="height: 60px; border-bottom: 1px solid #67C23A; display: flex;align-items: center">
      <div style="display: flex;align-items: center;padding-left: 20px" >
        <img src="../assets/imgs/logo.jpg" alt="" style="width: 60px; height: 60px;border-radius: 50%;">
        <span style="font-size: 20px;font-weight: bold;color: darksalmon;margin-left: 5px">山东黑陶文化</span>

      </div>


    </div>
  <!-- 头部区域结束 -->

得到: 

1.菜单展示

以下仅为示例,可根据自己需求来:

<el-menu
    default-active="2"
    class="el-menu-vertical-demo"
    @open="handleOpen"
    @close="handleClose"
>
  <el-sub-menu index="1">
    <template #title>
      <el-icon><location /></el-icon>
      <span>Navigator One</span>
    </template>
</el-sub-menu>>
</el-menu>

<div style="display: flex">
  <!-- 菜单区域开始 -->
  <div style="width: 240px;">
    <el-menu :default-openeds="['1']" default-active="/manager/home"  style="min-height: calc(100vh - 60px)">
      <el-menu-item index="/manager/home">
        <el-icon><House /></el-icon>>
        <span>首页</span>>
      </el-menu-item>
      <el-sub-menu index="1">
        <template #title>
          <el-icon><location /></el-icon>
          <span>数据管理</span>
        </template>
        <el-menu-item index="1-1">二级菜单</el-menu-item>
    </el-sub-menu>>
    </el-menu>
  </div>

 

嗯会有点小错误,用AI修正一下,在Mananger.vue内 再加上一些效果就得到:

<template>
  <div>
    <!-- 头部区域开始 -->
    <div style="height: 60px; display: flex;">
      <div style="width:240px;display: flex;align-items: center;padding-left: 20px;background-color: forestgreen">
        <img src="../assets/imgs/logo.jpg" alt="" style="width: 60px; height: 60px;border-radius: 50%;">
        <span style="font-size: 20px;font-weight: bold;color: darksalmon;margin-left: 5px">日照地方文化</span>
      </div>
<!--      <div style="flex: 1"></div>-->
<!--      <div style="width: fit-content;display: flex;align-items: center;">-->

    </div>
    <!-- 头部区域结束 -->

    <!-- 下方区域开始 -->
    <div style="display: flex">
      <!-- 菜单区域开始 -->
      <div style="width: 240px;box-shadow: 0 0 8px rgba(0,0,0, .12);">
        <el-menu :default-openeds="['1']" default-active="/manager/home" style="min-height: calc(100vh - 60px)">
          <el-menu-item index="/manager/home">
            <el-icon><House /></el-icon>
            <span>首页</span>
          </el-menu-item>
          <el-sub-menu index="1">
            <template #title>
              <el-icon><Location /></el-icon>
              <span>数据管理</span>
            </template>
            <el-menu-item index="1-1">二级菜单</el-menu-item>
          </el-sub-menu>
        </el-menu>
      </div>
      <!-- 菜单区域结束 -->

      <!-- 数据渲染区域开始 -->
      <div style="flex: 1;">
        <!-- 在这里添加你的内容 -->
      </div>
      <!-- 数据渲染区域结束 -->
    </div>
    <!-- 下方区域结束 -->
  </div>
</template>

<script setup>
import { House, Location } from '@element-plus/icons-vue'
</script>

<style scoped>
.el-menu {
  background-color: #7a9fe7;
  border: none;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.12);
}
.el-sub-menu__title {
  color: #ddd;
}
.el-menu-item {
  color: #ddd;
  height: 50px;
}
.el-menu .is-active {
  background-color: #0066CC;
  color: #ddd;
}
</style>

2.配置标题和logo:

复制粘贴代码可以获得右上角管理员名字和头像:

      <div style="width: fit-content;display: flex;align-items: center;padding-right: 20px;">
        <img style="width: 40px;height: 40px;border-radius: 50%" src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png" alt="">
        <span style="margin-left: 5px;">管理员</span>

添加管理员与logo:

①:
        <el-dropdown>
          <div style="display: flex;align-items: center;">
            <img style="width: 40px;height: 40px;border-radius: 50%" src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png" alt="">
            <span style="margin-left: 5px;">管理员</span>
          </div>
        </el-dropdown>

得到:

②:
          <template #dropdown>
            <el-dropdown-menu>
                <el-dropdown-item>个人信息</el-dropdown-item>
                <el-dropdown-item>修改密码</el-dropdown-item>
                <el-dropdown-item>退出登录</el-dropdown-item>
                <el-dropdown-item>查看收藏</el-dropdown-item>
                <el-dropdown-item>订单详情</el-dropdown-item>
            </el-dropdown-menu>
          </template>

得到:

 优化美观:

.el-dropdown{
  cursor: pointer;
}
.el-tooltip__trigger{
  outline:none;
}

划定边框:

 

修改一下颜色,得到:

3.设置主体区域

      <div style="flex: 1;width: 0;margin: 10px;background-color: #f5f7fe">

验证:

复制粘贴到Mananger.vue :

 验证:

.card{
    background-color: white;
    padding: 10px;
    border-radius: 5px;
    box-shadow: 0 0 8px rgba(0,0,0,0.12);
}

4. 设置查询和常用按钮:

<template>
  <div>
    <div class="card" style="margin-bottom: 5px;">

      <el-input
          style="width: 260px; margin-right: 5px;"
          v-model="data.name"
          placeholder="请输入名称查询"
          :prefix-icon="Search">
      </el-input>
      <el-button type="primary" :icon="Search" @click="search">查 询</el-button>
    </div>
    <div class="card" style="margin-bottom: 5px;">
      <el-button type="danger">批量删除</el-button>
      <el-button type="danger">新 增</el-button>
      <el-button type="danger">批量导入</el-button>
      <el-button type="danger">批量导出</el-button>
    </div>
  </div>
</template>

<script setup>
import { reactive } from 'vue';
import { Search } from '@element-plus/icons-vue';

// 定义数据模型
const data = reactive({
  name: null
});

// 添加 search 函数定义
const search = () => {
  console.log('搜索名称:', data.name);
  // 在这里添加具体的搜索逻辑
};
</script>

5. 设置表格,并填充内容:

代码如下:

<template>
  <div>
    <div class="card" style="margin-bottom: 5px;">
      <el-input
          style="width: 260px; margin-right: 5px;"
          v-model="data.name"
          placeholder="请输入名称查询"
          :prefix-icon="Search">
      </el-input>
      <el-button type="primary" :icon="Search" @click="search">查 询</el-button>
    </div>
    <div class="card" style="margin-bottom: 5px;">
      <el-button type="danger">批量删除</el-button>
      <el-button type="danger">新 增</el-button>
      <el-button type="danger">批量导入</el-button>
      <el-button type="danger">批量导出</el-button>
    </div>

    <!-- 表格部分 -->
    <div class="card" style="margin-bottom: 5px;">
      <el-table :data="filteredTableData" style="width: 100%">
        <el-table-column prop="name" label="名称" width="180" />
        <el-table-column prop="address" label="地址" width="180" />
        <el-table-column prop="collection" label="藏品" />
      </el-table>
    </div>
  </div>
</template>

<script setup>
import { reactive, computed } from 'vue';
import { Search } from '@element-plus/icons-vue';

// 定义数据模型
const data = reactive({
  name: null,
  tableData: [
    { name: '张三', address: '日照市博物馆', collection: '高柄镂孔蛋壳黑陶杯' },
    { name: '李四', address: '日照市博物馆', collection: '西周莱伯青铜鬲' },
    { name: '王五', address: '岚山区博物馆', collection: '玉石器' },
    { name: '赵六', address: '岚山区博物馆', collection: '红陶鬶' },
    { name: '钱七', address: '莒州博物馆', collection: '大口尊' },
    { name: '孙八', address: '莒州博物馆', collection: '玉琮' },
    { name: '钱九', address: '五莲县博物馆', collection: '玉璇玑' },
    { name: '孙十', address: '五莲县博物馆', collection: '大玉刀' },
    { name: '孙十一', address: '五莲县博物馆', collection: '鎏金铜佛' },
    { name: '孙十二', address: '东夷民俗文化博物馆', collection: '八大文化展厅' },
    { name: '孙十三', address: '东夷民俗文化博物馆', collection: '古玩以及民俗衍生品' },
    { name: '孙十四', address: '东夷黑陶博物馆', collection: '黑陶' },
    { name: '孙十五', address: '岚山区茶文化博物馆', collection: '制茶工具藏品' },
    { name: '孙十六', address: '岚山区茶文化博物馆', collection: '茶文化展' },
    { name: '孙十七', address: '世昌砚石博物馆', collection: '砚石艺术藏品' },
    { name: '孙十八', address: '赵氏石磨博物馆', collection: '石磨藏品' },
    { name: '孙十九', address: '日照贝壳博物馆', collection: '贝壳标本' },
  ]
});

// 计算属性:根据搜索条件过滤表格数据
const filteredTableData = computed(() => {
  if (!data.name) return data.tableData;
  return data.tableData.filter(item => item.name.includes(data.name));
});

// 添加 search 函数定义
const search = () => {
  console.log('搜索名称:', data.name);
  // 这里可以添加更多的搜索逻辑
};
</script>

验证: 

6.设置分页:

 

修改例子为:

 

 

得到:

 

现功能下 Home.vue内代码:

<template>
  <div>
    <div class="card" style="margin-bottom: 5px;">
      <el-input
          style="width: 260px; margin-right: 5px;"
          v-model="data.name"
          placeholder="请输入名称查询"
          :prefix-icon="Search">
      </el-input>
      <el-button type="primary" :icon="Search" @click="search">查 询</el-button>
    </div>

    <div class="card" style="margin-bottom: 5px;">
      <el-button type="danger">批量删除</el-button>
      <el-button type="danger">新 增</el-button>
      <el-button type="danger">批量导入</el-button>
      <el-button type="danger">批量导出</el-button>
    </div>

    <!-- 表格部分 -->
    <div class="card" style="margin-bottom: 5px;">
      <el-table :data="filteredTableData" style="width: 100%":header-cell-style="{ color: '#333', backgroundColor: '#f2f8fb' }">
        <el-table-column prop="name" label="名称" width="180" />
        <el-table-column prop="address" label="地址" width="180" />
        <el-table-column prop="collection" label="藏品" />
      </el-table>
    </div>
    <div class="card" >
      <el-pagination
          v-model:current-page="data.pageNum"
          :page-size="data.pageSize"
          layout="total, prev, pager, next"
          :total="data.total"
      />
    </div>
  </div>
</template>

<script setup>
import { reactive, computed } from 'vue';
import { Search } from '@element-plus/icons-vue';

// 定义数据模型
const data = reactive({
  name: null,
  pageNum: 2,
  size: 6,
  total:19,
  tableData: [
    { name: '张三', address: '日照市博物馆',  collection: '高柄镂孔蛋壳黑陶杯' },
    { name: '李四', address: '日照市博物馆', collection: '西周莱伯青铜鬲' },
    { name: '王五', address: '岚山区博物馆', collection: '玉石器' },
    { name: '赵六', address: '岚山区博物馆', collection: '红陶鬶' },
    { name: '钱七', address: '莒州博物馆', collection: '大口尊' },
    { name: '孙八', address: '莒州博物馆', collection: '玉琮' },
    { name: '钱九', address: '五莲县博物馆', collection: '玉璇玑' },
    { name: '孙十', address: '五莲县博物馆', collection: '大玉刀' },
    { name: '孙十一', address: '五莲县博物馆', collection: '鎏金铜佛' },
    { name: '孙十二', address: '东夷民俗文化博物馆', collection: '八大文化展厅' },
    { name: '孙十三', address: '东夷民俗文化博物馆', collection: '古玩以及民俗衍生品' },
    { name: '孙十四', address: '东夷黑陶博物馆', collection: '黑陶' },
    { name: '孙十五', address: '岚山区茶文化博物馆', collection: '制茶工具藏品' },
    { name: '孙十六', address: '岚山区茶文化博物馆', collection: '茶文化展' },
    { name: '孙十七', address: '世昌砚石博物馆', collection: '砚石艺术藏品' },
    { name: '孙十八', address: '赵氏石磨博物馆', collection: '石磨藏品' },
    { name: '孙十九', address: '日照贝壳博物馆', collection: '贝壳标本' },
  ]
});

// 计算属性:根据搜索条件过滤表格数据
const filteredTableData = computed(() => {
  if (!data.name) return data.tableData;
  return data.tableData.filter(item => item.name.includes(data.name));
});

// 添加 search 函数定义
const search = () => {
  console.log('搜索名称:', data.name);
  // 这里可以添加更多的搜索逻辑
};
</script>

现功能下 Mananger.vue内代码: 

<template>
  <div>
    <!-- 头部区域开始 -->
    <div style="height: 60px; display: flex;">
      <div style="width:240px;display: flex;align-items: center;padding-left: 20px;background-color: #0066CC">
        <img src="../assets/imgs/logo.jpg" alt="" style="width: 60px; height: 60px;border-radius: 50%;">
        <span style="font-size: 20px;font-weight: bold;color: darksalmon;margin-left: 5px">日照地方文化</span>
      </div>
      <div style="flex: 1;border-bottom: 1px solid #6fa4f5"></div>
      <div style="width: fit-content;padding-right: 20px;display: flex;align-items: center;border-bottom: 1px solid #6fa4f5">
        <el-dropdown>
          <div style="display: flex;align-items: center;">
            <img style="width: 40px;height: 40px;border-radius: 50%" src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png" alt="">
            <span style="margin-left: 5px;">管理员</span>
          </div>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item>个人信息</el-dropdown-item>
              <el-dropdown-item>修改密码</el-dropdown-item>
              <el-dropdown-item>退出登录</el-dropdown-item>
              <el-dropdown-item>查看收藏</el-dropdown-item>
              <el-dropdown-item>订单详情</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div>
    <!-- 头部区域结束 -->

    <!-- 下方区域开始 -->
    <div style="display: flex">
      <!-- 菜单区域开始 -->
      <div style="width: 240px; box-shadow: 0 0 8px rgba(0, 0, 0, 0.12); height: calc(100vh - 60px); background-color: #0066CC;">
        <el-menu router :default-openeds="['1']" default-active="/manager/home" style="min-height: calc(100vh - 60px)">
          <el-menu-item index="/manager/home">
            <el-icon><House /></el-icon>
            <span>首页</span>
          </el-menu-item>
          <el-sub-menu index="1">
            <template #title>
              <el-icon><Location /></el-icon>
              <span>数据管理</span>
            </template>
            <el-menu-item index="1-1">二级菜单</el-menu-item>
          </el-sub-menu>
        </el-menu>
      </div>
      <!-- 菜单区域结束 -->

      <!-- 数据渲染区域开始 -->
      <div style="flex: 1; width: 0; margin: 10px; background-color: #ecf0fc">
        <RouterView />
        <!-- 在这里添加你的内容 -->
      </div>

      <!-- 数据渲染区域结束 -->

    </div>

    <!-- 下方区域结束 -->
  </div>
</template>

<script setup>
import { House, Location } from '@element-plus/icons-vue'
</script>

<style scoped>
.el-menu {
  border: none;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.12);
}
.el-sub-menu__title {
  color: #dfe9f9;
}
.el-menu-item {/*二级菜单颜色*/
  color: #49515b;
  height: 50px;
}
.el-menu .is-active {
  background-color: #7a9fe7;/*首页颜色*/
  color: #f8f3f2;
}
.el-sub-menu__title > .el-icon,
.el-menu-item > .el-icon {
  color: #4c5463;
}
.el-dropdown {
  cursor: pointer;
}
.el-tooltip__trigger {
  outline: none;
}
</style>

 7.动态路径分页显示:

      {path: '/manager/about',   component: import('../views/About.vue'),},

 elmanu路由变化通过router,这样一个属性:

总体Mananger.vue代码如下:

<template>
  <div>
    <!-- 头部区域开始 -->
    <div style="height: 60px; display: flex;">
      <div style="width:240px;display: flex;align-items: center;padding-left: 20px;background-color: #0066CC">
        <img src="../assets/imgs/logo.jpg" alt="" style="width: 60px; height: 60px;border-radius: 50%;">
        <span style="font-size: 20px;font-weight: bold;color: darksalmon;margin-left: 5px">日照地方文化</span>
      </div>
      <div style="flex: 1;border-bottom: 1px solid #6fa4f5"></div>
      <div style="width: fit-content;padding-right: 20px;display: flex;align-items: center;border-bottom: 1px solid #6fa4f5">
        <el-dropdown>
          <div style="display: flex;align-items: center;">
            <img style="width: 40px;height: 40px;border-radius: 50%" src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png" alt="">
            <span style="margin-left: 5px;">管理员</span>
          </div>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item>个人信息</el-dropdown-item>
              <el-dropdown-item>修改密码</el-dropdown-item>
              <el-dropdown-item>退出登录</el-dropdown-item>
              <el-dropdown-item>查看收藏</el-dropdown-item>
              <el-dropdown-item>订单详情</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div>
    <!-- 头部区域结束 -->

    <!-- 下方区域开始 -->
    <div style="display: flex">
      <!-- 菜单区域开始 -->
      <div style="width: 240px; box-shadow: 0 0 8px rgba(0, 0, 0, 0.12); height: calc(100vh - 60px); background-color: #0066CC;">
        <el-menu router :default-openeds="['1']" :default-active="$route.path" style="min-height: calc(100vh - 60px)">
          <el-menu-item index="/manager/home">
            <el-icon><House /></el-icon>
            <span>首页</span>
          </el-menu-item>
          <el-sub-menu index="1">
            <template #title>
              <el-icon><Location /></el-icon>
              <span>数据管理</span>
            </template>
            <el-menu-item index="/manager/about">关于数据</el-menu-item>
          </el-sub-menu>
        </el-menu>
      </div>
      <!-- 菜单区域结束 -->

      <!-- 数据渲染区域开始 -->
      <div style="flex: 1; width: 0; margin: 10px; background-color: #ecf0fc">
        <RouterView />
        <!-- 在这里添加你的内容 -->
      </div>

      <!-- 数据渲染区域结束 -->

    </div>

    <!-- 下方区域结束 -->
  </div>
</template>

<script setup>
import { useRoute } from 'vue-router';
import { House, Location } from '@element-plus/icons-vue';

const route = useRoute();
</script>

<style scoped>
.el-menu {
  border: none;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.12);
}
.el-sub-menu__title {
  color: #dfe9f9;
}
.el-menu-item {/*二级菜单颜色*/
  color: #49515b;
  height: 50px;
}
.el-menu .is-active {
  background-color: #7a9fe7;/*首页颜色*/
  color: #f8f3f2;
}
.el-sub-menu__title > .el-icon,
.el-menu-item > .el-icon {
  color: #4c5463;
}
.el-dropdown {
  cursor: pointer;
}
.el-tooltip__trigger {
  outline: none;
}
.el-menu--inline.el-menu-item{
  padding-left:45px !important;
}
</style>

总体About.vue代码如下: 

<template>
  <div>
    <h1>日照地方文化数字博物馆藏品搜索系统</h1>
    <p>这是关于页面的内容</p>
  </div>
</template>

<script setup>
import { ref } from 'vue';

// 组件逻辑可以放在这里
const message = ref('来自关于页面的问候!');
</script>

<style scoped>
/* 可选的样式 */
</style>

总体index.js代码如下:

import { createRouter, createWebHistory } from 'vue-router'


const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {path: '/',   component: import('../views/Mananger.vue'),
    children: [
      {path: '/manager/home',   component: import('../views/Home.vue'),},
      {path: '/manager/about',   component: import('../views/About.vue'),},
    ]
    },

    {path: '/notFound',   component: import('../views/404.vue')},
    {path: '/:pathMatch(.*)*', redirect: '/notFound'},

  ],
})

export default router

得到:

大功告成!!!

三、附件

参考视频: 

【带小白做毕设】02. 使用Vue3集成Element-Plus快速搭建一个管理系统的页面框架_哔哩哔哩_bilibili 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值