vue cli学生管理系统代码
时间: 2023-10-19 16:05:19 浏览: 89
由于一个完整的学生管理系统涉及到很多功能和模块,代码量非常大,这里提供一个基本的代码框架,供您参考。
1. App.vue
```vue
<template>
<div id="app">
<header>
<h1>学生信息管理系统</h1>
</header>
<router-view></router-view>
</div>
</template>
<script>
export default {
name: "App",
};
</script>
<style>
/* 样式 */
</style>
```
2. Home.vue
```vue
<template>
<div>
<h2>欢迎使用学生信息管理系统</h2>
<router-link to="/student">学生列表</router-link>
</div>
</template>
<script>
export default {
name: "Home",
};
</script>
<style>
/* 样式 */
</style>
```
3. StudentList.vue
```vue
<template>
<div>
<h2>学生列表</h2>
<table>
<thead>
<tr>
<th>学号</th>
<th>姓名</th>
<th>性别</th>
<th>出生日期</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr v-for="student in students" :key="student.id">
<td>{{ student.id }}</td>
<td>{{ student.name }}</td>
<td>{{ student.gender }}</td>
<td>{{ student.birthdate }}</td>
<td>
<router-link :to="{ name: 'student-detail', params: { id: student.id }}">
查看详情
</router-link>
</td>
</tr>
</tbody>
</table>
</div>
</template>
<script>
export default {
name: "StudentList",
data() {
return {
students: [
{ id: 1, name: "张三", gender: "男", birthdate: "1999-01-01" },
{ id: 2, name: "李四", gender: "女", birthdate: "1998-02-02" },
{ id: 3, name: "王五", gender: "男", birthdate: "1997-03-03" },
],
};
},
};
</script>
<style>
/* 样式 */
</style>
```
4. StudentDetail.vue
```vue
<template>
<div>
<h2>学生详情</h2>
<p>学号:{{ student.id }}</p>
<p>姓名:{{ student.name }}</p>
<p>性别:{{ student.gender }}</p>
<p>出生日期:{{ student.birthdate }}</p>
</div>
</template>
<script>
export default {
name: "StudentDetail",
data() {
return {
student: {},
};
},
mounted() {
const id = this.$route.params.id; // 获取路由参数
this.student = this.getStudentById(id); // 根据学号获取学生详情
},
methods: {
getStudentById(id) {
// 模拟从服务器获取学生详情
return { id: id, name: "张三", gender: "男", birthdate: "1999-01-01" };
},
},
};
</script>
<style>
/* 样式 */
</style>
```
5. index.js
```js
import Vue from "vue";
import VueRouter from "vue-router";
import App from "./App.vue";
import Home from "./components/Home.vue";
import StudentList from "./components/StudentList.vue";
import StudentDetail from "./components/StudentDetail.vue";
Vue.use(VueRouter);
const routes = [
{
path: "/",
component: Home,
},
{
path: "/student",
component: StudentList,
},
{
path: "/student/:id",
name: "student-detail",
component: StudentDetail,
},
];
const router = new VueRouter({
routes,
mode: "history",
});
Vue.config.productionTip = false;
new Vue({
router,
render: (h) => h(App),
}).$mount("#app");
```
以上是一个基本的学生管理系统代码框架,包含了主页、学生列表和学生详情三个页面,可以根据实际需求进行修改和扩展。
阅读全文