第四次作业前端代码
This commit is contained in:
commit
a915bbb200
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Vite App</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.js"></script>
|
||||
</body>
|
||||
</html>
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"name": "vue3_cli_default",
|
||||
"version": "0.0.0",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"serve": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^1.7.7",
|
||||
"element-plus": "^2.8.7",
|
||||
"vue": "^3.2.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^1.6.0",
|
||||
"@vue/compiler-sfc": "^3.2.6",
|
||||
"vite": "^2.5.2"
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 4.2 KiB |
|
@ -0,0 +1,137 @@
|
|||
<script setup>
|
||||
import { ref,onMounted,reactive } from 'vue';
|
||||
import axios from 'axios';
|
||||
|
||||
const msg = ref("hello world 1234")
|
||||
//生命周期方法
|
||||
onMounted( () =>{
|
||||
console.log("onMounted")
|
||||
myClick()
|
||||
} )
|
||||
|
||||
|
||||
const studentList = ref(null)
|
||||
function myClick(){
|
||||
axios({
|
||||
method:'GET',
|
||||
url:'http://127.0.0.1:8080/student/BookList11'
|
||||
}).then( res => {
|
||||
console.log(res.data)
|
||||
//显示数据
|
||||
studentList.value = res.data.data
|
||||
}).catch( err => {
|
||||
console.log(err)
|
||||
})
|
||||
}
|
||||
|
||||
function deleteStudent(row){
|
||||
console.log(row)
|
||||
axios({
|
||||
method:'POST',
|
||||
url:'http://127.0.0.1:8080/student/deleteBookList',
|
||||
params:{
|
||||
id:row.id
|
||||
}
|
||||
}).then(res => {
|
||||
console.log(res.data)
|
||||
myClick()
|
||||
}).catch(err => {
|
||||
console.log(err)
|
||||
})
|
||||
}
|
||||
|
||||
const dialogVisible = ref (false)
|
||||
const form = reactive({
|
||||
id:null,
|
||||
age:0,
|
||||
name:''
|
||||
})
|
||||
|
||||
function updateStudent(row){
|
||||
console.log(row)
|
||||
dialogVisible.value = true
|
||||
Object.assign(from,row)
|
||||
}
|
||||
|
||||
function updateMyStudent(){
|
||||
axios({
|
||||
method:'POST',
|
||||
url:'http://127.0.0.1:8080/student/updateBookList',
|
||||
params:form
|
||||
|
||||
}).then( res => {
|
||||
console.log(res.data)
|
||||
dialogVisible.value = false
|
||||
myClick()
|
||||
})
|
||||
.catch( err => {
|
||||
console.log(err)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function addStudent(){
|
||||
dialogVisible.value = true
|
||||
Object.assign(from,{
|
||||
id:null,
|
||||
age:0,
|
||||
name:''
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
<template>
|
||||
<!-- 增 改 删 查 -->
|
||||
<h1 style="text-align: center;">书籍列表</h1>
|
||||
<el-button @click="dialogVisible = true">增加</el-button>
|
||||
<el-table :data="studentList" stripe style="width: 100%">
|
||||
<el-table-column prop="id" label="id" width="180" />
|
||||
<el-table-column prop="age" label="年龄" width="180" />
|
||||
<el-table-column prop="name" label="姓名" />
|
||||
<el-table-column fixed="right" label="操作" min-width="120">
|
||||
<template #default="{row}">
|
||||
<el-button type="danger" size="small" @click="deleteStudent(row)">
|
||||
删除
|
||||
</el-button>
|
||||
<el-button type="primary" size="small" @click="updateStudent(row)">
|
||||
编辑
|
||||
</el-button>
|
||||
</template>
|
||||
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-dialog
|
||||
v-model="dialogVisible"
|
||||
title="增加或修改用户"
|
||||
width="500"
|
||||
:before-close="handleClose"
|
||||
>
|
||||
<el-form :model="form" label-width="auto" style="max-width: 600px">
|
||||
<el-form-item label="id">
|
||||
<el-input v-model="form.id" hidden />
|
||||
</el-form-item>
|
||||
<el-form-item label="年龄">
|
||||
<el-input v-model="form.age" />
|
||||
</el-form-item>
|
||||
<el-form-item label="姓名">
|
||||
<el-input v-model="form.name" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="updateMyStudent()">
|
||||
确认
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
|
||||
</style>
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 6.7 KiB |
|
@ -0,0 +1,38 @@
|
|||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
|
||||
defineProps({
|
||||
msg: String
|
||||
})
|
||||
|
||||
const count = ref(0)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<h1>{{ msg }}</h1>
|
||||
|
||||
<p>
|
||||
Welcome:
|
||||
<a href="https://hx.dcloud.net.cn/" target="_blank">HBuilderX</a>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<a href="https://vitejs.dev/guide/features.html" target="_blank">
|
||||
Vite Documentation
|
||||
</a>
|
||||
|
|
||||
<a href="https://v3.vuejs.org/" target="_blank">Vue 3 Documentation</a>
|
||||
</p>
|
||||
|
||||
<button type="button" @click="count++">count is: {{ count }}</button>
|
||||
<p>
|
||||
Edit
|
||||
<code>components/HelloWorld.vue</code> to test hot module replacement.
|
||||
</p>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
a {
|
||||
color: #42b983;
|
||||
}
|
||||
</style>
|
|
@ -0,0 +1,10 @@
|
|||
// main.ts
|
||||
import { createApp } from 'vue'
|
||||
import ElementPlus from 'element-plus'
|
||||
import 'element-plus/dist/index.css'
|
||||
import App from './App.vue'
|
||||
|
||||
const app = createApp(App)
|
||||
|
||||
app.use(ElementPlus)
|
||||
app.mount('#app')
|
|
@ -0,0 +1,8 @@
|
|||
import {createRouter,createWebHashHistory} from 'vue-router';
|
||||
|
||||
const router = createRouter({
|
||||
history:createWebHashHistory(),
|
||||
routes
|
||||
});
|
||||
|
||||
export default router;
|
|
@ -0,0 +1,7 @@
|
|||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [vue()]
|
||||
})
|
Loading…
Reference in New Issue