当前位置:首页 > VUE

用vue实现系统首页

2026-02-24 12:56:13VUE

使用Vue实现系统首页

项目初始化

使用Vue CLI创建新项目:

vue create system-homepage
cd system-homepage

安装常用依赖:

npm install axios vue-router element-ui

目录结构

典型目录结构如下:

src/
├── assets/          # 静态资源
├── components/      # 公共组件
│   ├── Header.vue
│   ├── Sidebar.vue
│   └── Footer.vue
├── views/           # 页面视图
│   ├── Home.vue
│   ├── Dashboard.vue
│   └── About.vue
├── router/          # 路由配置
│   └── index.js
├── App.vue          # 根组件
└── main.js          # 入口文件

基础布局实现

在App.vue中设置基础布局框架:

用vue实现系统首页

<template>
  <div id="app">
    <Header />
    <div class="main-container">
      <Sidebar />
      <router-view class="content"/>
    </div>
    <Footer />
  </div>
</template>

<script>
import Header from './components/Header'
import Sidebar from './components/Sidebar'
import Footer from './components/Footer'

export default {
  components: { Header, Sidebar, Footer }
}
</script>

<style>
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.main-container {
  display: flex;
  flex: 1;
}
.content {
  flex: 1;
  padding: 20px;
}
</style>

路由配置

在router/index.js中配置基本路由:

import Vue from 'vue'
import Router from 'vue-router'
import Home from '../views/Home.vue'
import Dashboard from '../views/Dashboard.vue'

Vue.use(Router)

export default new Router({
  routes: [
    { path: '/', name: 'home', component: Home },
    { path: '/dashboard', name: 'dashboard', component: Dashboard }
  ]
})

首页组件实现

views/Home.vue示例:

用vue实现系统首页

<template>
  <div class="home">
    <h1>欢迎来到系统首页</h1>
    <el-card class="box-card">
      <div slot="header">
        <span>系统公告</span>
      </div>
      <div v-for="(item,index) in notices" :key="index">
        {{ item.title }} - {{ item.date }}
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      notices: [
        { title: '系统维护通知', date: '2023-05-01' },
        { title: '新功能上线', date: '2023-04-15' }
      ]
    }
  }
}
</script>

<style scoped>
.home {
  padding: 20px;
}
.box-card {
  margin-top: 20px;
  width: 80%;
}
</style>

数据请求封装

创建utils/request.js封装axios:

import axios from 'axios'

const service = axios.create({
  baseURL: process.env.VUE_APP_BASE_API,
  timeout: 5000
})

service.interceptors.request.use(
  config => {
    return config
  },
  error => {
    return Promise.reject(error)
  }
)

export default service

响应式设计

使用媒体查询实现响应式:

@media screen and (max-width: 768px) {
  .main-container {
    flex-direction: column;
  }
  .box-card {
    width: 100%;
  }
}

部署准备

配置vue.config.js:

module.exports = {
  publicPath: process.env.NODE_ENV === 'production'
    ? '/system-homepage/'
    : '/',
  outputDir: 'dist',
  assetsDir: 'static'
}

这个实现方案包含了系统首页的基本框架,可根据实际需求扩展功能模块,如添加用户登录状态管理、权限控制等功能。Element UI组件库提供了丰富的UI组件可以快速构建界面,axios处理数据请求,vue-router管理页面路由。

标签: 首页系统
分享给朋友:

相关文章

vue实现一个插件系统

vue实现一个插件系统

实现插件系统的核心思路 Vue的插件系统允许通过Vue.use()注册全局功能,通常包含以下要素: 暴露install方法供Vue调用 添加全局资源(指令/过滤器/组件等) 注入组件选项 添加实例…

vue实现平台系统

vue实现平台系统

Vue 实现平台系统的方法 项目初始化与配置 使用 Vue CLI 或 Vite 初始化项目,推荐 Vue 3 + TypeScript 组合。安装核心依赖: npm create vue@lat…

vue实现商城首页

vue实现商城首页

Vue 实现商城首页的关键步骤 项目初始化 使用 Vue CLI 创建项目,安装必要依赖如 vue-router、axios、vuex 等。配置基础路由和 store 结构。 页面布局设计 采用…

vue实现刷新跳转首页

vue实现刷新跳转首页

Vue 实现刷新跳转首页的方法 在 Vue 项目中,实现刷新后跳转首页可以通过以下几种方式实现,具体选择取决于项目需求和路由配置。 使用路由守卫 在路由配置中,通过全局前置守卫 beforeEach…

vue实现审批首页设计

vue实现审批首页设计

Vue实现审批首页设计 设计审批首页布局 审批首页通常包含待办事项、已办事项、审批统计等模块。使用Vue的组件化开发方式,可以将首页拆分为多个子组件,如待办列表、已办列表、统计卡片等。 <te…

vue实现图书购买系统

vue实现图书购买系统

Vue实现图书购买系统 项目结构设计 使用Vue CLI或Vite初始化项目,推荐目录结构: src/components/ 存放可复用组件(如图书卡片、购物车) src/views/ 存放页面级组…