前端代码运行不成功

This commit is contained in:
Stella 2024-11-11 01:15:45 +08:00
commit a5b5cd750b
10 changed files with 1302 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/node_modules

13
index.html Normal file
View File

@ -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>

1110
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

17
package.json Normal file
View File

@ -0,0 +1,17 @@
{
"name": "vue3_cli_default",
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"serve": "vite preview"
},
"dependencies": {
"vue": "^3.2.8"
},
"devDependencies": {
"@vitejs/plugin-vue": "^1.6.0",
"@vue/compiler-sfc": "^3.2.6",
"vite": "^2.5.2"
}
}

BIN
public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

136
src/App.vue Normal file
View File

@ -0,0 +1,136 @@
<script setup>
import { ref,onMounted,reactive } from 'vue';
import axios from 'axios';
const msg=ref("hello world 1234")
onMounted(()=>{
console.log("onMounted")
myClick()
})
const BookList=ref(null)
function myClick(){
axios({
method:'GET',
url:'http://127.0.0.1:8080/bookList/BookList11'
}).then(res =>{
console.log(res.data)
//
BookList.value=res.data.data
}).catch(err =>{
console.log(err)
})
}
const mycolor=ref("red")
const username=ref('')
const password=ref('')
function deleteBook(row){
console.log(row)
axios({
method:'POST',
url:'http://127.0.0.1:8080/bookList/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 updateBook(row) {
console.log(row)
dialogVisible.value = true
// row -> form
Object.assign(form, row)
}
function updateMyBook() {
axios({
method: 'POST',
url: 'http://127.0.0.1:8080/bookList/updateBookList',
params: form
}).then(res => {
console.log(res.data)
dialogVisible.value = false
myClick()
}).catch(err => {
console.log(err)
})
}
function addBook() {
dialogVisible.value = true
Object.assign(form, {
id: null,
age: 0,
name: ''
})
}
</script>
<template>
<h1 style="text-align: center;">图书列表</h1>
<el-button @click="addBook">增加</el-button>
<el-table :data="BookList" stripe style="width: 100%">
<el-table-column prop="id" label="id" width="160" />
<el-table-column prop="title" label="书名" width="160" />
<el-table-column prop="author" label="作者" width="160"/>
<el-table-column prop="isbn" label="出版编号" width="160" />
<el-table-column prop="publisher" label="出版社" width="160" />
<el-table-column prop="published_date" label="出版时间" width="160"/>
<el-table-column fixed="right" label="操作" min-width="120">
<template #default="{row}">
<el-button type="danger" size="small" @click="deleteBook(row)">
删除
</el-button>
<el-button type="primary" size="small" @click="updateBook(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 disabled v-model="form.id" />
</el-form-item>
<el-form-item label="书名">
<el-input v-model="form.title" />
</el-form-item>
<el-form-item label="作者">
<el-input v-model="form.author" />
</el-form-item>
<el-form-item label="出版编号">
<el-input v-model="form.isbn" />
</el-form-item>
<el-form-item label="出版社">
<el-input v-model="form.publisher" />
</el-form-item>
<el-form-item label="出版时间">
<el-input v-model="form.published_date" />
</el-form-item>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="updateMyBook()">
确认
</el-button>
</div>
</template>
</el-dialog>
</template>
<style>
</style>

BIN
src/assets/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

8
src/components/router.js Normal file
View File

@ -0,0 +1,8 @@
import {createRouter,createWebHashHistory} from 'vue-router';
const router = createRouter({
history:createWebHashHistory(),
routes
});
export default router;

10
src/main.js Normal file
View File

@ -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')

7
vite.config.js Normal file
View File

@ -0,0 +1,7 @@
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()]
})