当前位置: 首页 > news >正文

从0开始搭建vue + flask 旅游景点数据分析系统(二):搭建基础框架

这一期目标是把系统的布局给搭建起来,采用一个非常简单的后端管理风格,可以参考官方的页面
https://element.eleme.cn/#/zh-CN/component/container

下面我们开始搭建,首先,安装一下vue-router,element-ui

npm install vue-router@3
npm install element-ui

然后在src目录下创建layouts文件夹和router文件夹 ,

在layouts文件夹下建立Layout.vue文件

<template><el-container class="container"><el-aside width="200px" style="background-color: rgb(229,227,238)"><el-menu :default-active="activeIndex" active-text-color="#BAA7FFFF"	class="el-menu-vertical"><el-menu-item index="/dashboard" @click="navigateTo('/dashboard')">Dashboard</el-menu-item><el-menu-item index="/users" @click="navigateTo('/users')">Users</el-menu-item><!-- 其他菜单项 --></el-menu></el-aside><el-container><el-header class="header"><div class="logo">My Admin</div></el-header><el-main class="main"><router-view></router-view></el-main></el-container></el-container>
</template><script>
export default {data() {return {activeIndex: '/dashboard'};},methods: {navigateTo(path) {console.log(this.activeIndex);if (this.$route.path !== path) {this.activeIndex = path;this.$router.push(path);}}}
};
</script><style scoped>
.container{height: 100vh;border: 1px solid #eee;
}.header {background-color: #ffffff;text-align: center;line-height: 60px;border-bottom: 1px solid #ebeef5;
}.logo {font-size: 20px;font-weight: bold;
}.main {padding: 20px;
}
</style>

在router下建立index.js文件,

import Vue from 'vue';
import Router from 'vue-router';
import Layout from '@/layouts/Layout';// 引入页面组件
import Dashboard from '@/views/Dashboard';
import Users from '@/views/Users';Vue.use(Router);const routes = [{path: '/',component: Layout,redirect: '/dashboard',children: [{path: 'dashboard',component: Dashboard,name: 'Dashboard'},{path: 'users',component: Users,name: 'Users'}// 其他子路由]},// 其他路由
];const router = new Router({mode: 'history',routes
});export default router;

因为想访问 / 直接转到 /dashboard ,所以有这行设置:

 redirect: '/dashboard',

还需要新建views文件夹,新增两个vue文件Dashboard.vue和Users.vue

<!-- Dashboard.vue -->
<template><div className="dashboard"><h1>Dashboard</h1><!-- Dashboard 内容 --></div>
</template><script>
export default {name: 'Dashboard'
};
</script><style scoped>
.dashboard {/* 样式 */
}
</style><!-- Users.vue -->
<template><div class="users"><h1>Users</h1><!-- Users 内容 --></div>
</template><script>
export default {name: 'Users'
};
</script><style scoped>
.users {/* 样式 */
}
</style>

修改main.js ,引入上面我们新增的内容:

import Vue from 'vue'
import App from './App.vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import router from './router'Vue.use(ElementUI)Vue.config.productionTip = falsenew Vue({router,render: h => h(App),
}).$mount('#app')

运行程序:

npm run serve

效果:
在这里插入图片描述

http://www.lryc.cn/news/408198.html

相关文章:

  • 【过滤器 vs 拦截器】SpringBoot中过滤器与拦截器:明智选择的艺术(如何在项目中做出明智选择)
  • 2024-06学习笔记
  • 【VUE】封装一个追随鼠标的漂浮组件框架
  • mapstruct与lombok结合使用
  • 【SpringBoot】Web开发之URL映射
  • 对递归的一些理解。力扣206题:翻转链表
  • Kafka面试三道题
  • C/C++编程-算法学习-数字滤波器
  • maven介绍 搭建Nexus3(maven私服搭建)
  • 电商项目之如何判断线程池是否执行完所有任务
  • 【前端 15】Vue生命周期
  • PCIe总线-Linux内核PCIe软件框架分析(十一)
  • 视觉SLAM第二讲
  • mysql1055报错解决方法
  • Java的@DateTimeFormat注解与@JsonFormat注解的使用对比
  • 德国云手机:企业移动办公解决方案
  • 【React】useState:状态管理的基石
  • 商品中心关于缓存热key的解决方案
  • 【Python系列】Parquet 数据处理与合并:高效数据操作实践
  • 大脑自组织神经网络通俗讲解
  • org.springframework.context.annotation.DeferredImportSelector如何使用?
  • 缓慢变化维
  • Vue常用的指令都有哪些?都有什么作用?什么是自定义指令?
  • kettle从入门到精通 第八十一课 ETL之kettle kettle中的json对象字段写入postgresql中的json字段正确姿势
  • 计算机网络实验-RIP配置与分析
  • 33.【C语言】实践扫雷游戏
  • git学习笔记(总结了常见命令与学习中遇到的问题和解决方法)
  • 【计算机网络】TCP协议详解
  • 2.3 大模型硬件基础:AI芯片(上篇) —— 《带你自学大语言模型》系列
  • Java | Leetcode Java题解之第279题完全平方数