diff --git "a/\345\215\242\346\200\235\346\207\277/20250519_\350\257\276\345\240\202\347\254\224\350\256\260+\344\275\234\344\270\232.md" "b/\345\215\242\346\200\235\346\207\277/20250519_\350\257\276\345\240\202\347\254\224\350\256\260+\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..05e0c090eb87c2af6f82d0766451827405d4f88e --- /dev/null +++ "b/\345\215\242\346\200\235\346\207\277/20250519_\350\257\276\345\240\202\347\254\224\350\256\260+\344\275\234\344\270\232.md" @@ -0,0 +1,109 @@ +# 笔记 +## 完成后端的路由请求和数据库创建 +### 未封装路由 +```js +import Koa from 'koa' +import Router from 'koa-router' +import bodyParser from 'koa-bodyparser' +import cors from'@koa/cors' +import { Sequelize, DataTypes, where, Op } from 'sequelize' +const router = new Router() +const app = new Koa() +const port = 8080 +app.use(cors()) +app.use(bodyParser()) +// 建立数据库 +//1. 初始化 +let sequelize = new Sequelize('BookDB', 'root', '123456', { + dialect: "mysql", + host: 'localhost' +}) +// 2. 创建表 +let Booktb = sequelize.define('bookdb', { + bookName: { + type: DataTypes.STRING, + allowNull: false + }, + author: { + type: DataTypes.STRING, + allowNull: true + }, + price: { + type: DataTypes.INTEGER, + allowNull: true + } +}) +// 3. 运行 +await sequelize.sync() + +// ----------------------------------------------- +//查找,过滤 +router.get('/book', async (ctx, next) => { + let keyword =ctx.request.query.keyword || '' + let where =null + if(keyword.trim()){ + where={ + [Op.or]:{ + bookName:{ + [Op.like]:`%${keyword}%` + }, + author:{ + [Op.like]:`%${keyword}%` + } + } + } + } + const obj =await Booktb.findAll({where}) + ctx.body = { + code: 888, + data: obj, + msg: 'success' + } +}) +//单个对象 +router.get('/book/:id', async (ctx, next) => { + let id = ctx.params.id || 0 + let obj = await Booktb.findByPk(id) + ctx.body = { + code: 888, + data: obj, + msg: 'success' + } +}) +//新增 +router.post('/book', async (ctx, next) => { + let obj = ctx.request.body + let res = await Booktb.create(obj) + ctx.body = { + code: 888, + data: res, + msg: 'success' + } +}) +//修改 +router.put('/book/:id', async (ctx, next) => { + let id = ctx.params.id||0 + let obj = ctx.request.body + let res = await Booktb.update(obj, { where: { id } }) + ctx.body = { + code: 888, + data: res, + msg: 'success' + } +}) +//删除 +router.delete('/book/:id', async (ctx, next) => { + let id = ctx.params.id ||0 + let res = await Booktb.destroy({where:{id}}) + ctx.body = { + code: 888, + data: res, + msg: 'success' + } +}) +// ----------------------------------------------- +app.use(router.routes()) +app.listen(port, () => { + console.log(`服务运行在:http://localhost:${port}`) +}) +``` \ No newline at end of file diff --git "a/\345\215\242\346\200\235\346\207\277/20250520_\350\257\276\345\240\202\347\254\224\350\256\260+\344\275\234\344\270\232.md" "b/\345\215\242\346\200\235\346\207\277/20250520_\350\257\276\345\240\202\347\254\224\350\256\260+\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..6811a2bbc6141c6a8d70b58aad226a3da19de29e --- /dev/null +++ "b/\345\215\242\346\200\235\346\207\277/20250520_\350\257\276\345\240\202\347\254\224\350\256\260+\344\275\234\344\270\232.md" @@ -0,0 +1,142 @@ +# 笔记 +## 完成前端页面设计和axios请求 +### 页面功能核心 +```js +<----- 列表页------> + + + +<------ 新增或编辑页 ------> + + +``` +### api功能接口 +```js +const url = 'http://localhost:8080' +import axios from "axios" +//请求数据 +export const fetchAllData = async (keyword) => { + let data; + if (keyword) { + data = await axios.get(`${url}/book?keyword=${keyword}`) + } + else { + data = await axios.get(`${url}/book`) + + } + return data.data +} +//请求单个数据 +export const fetchSingleData = async (id) => { + let data = await axios.get(`${url}/book/${id}`) + return data.data +} +//新增数据 +export const fetchAddDate = async (obj) => { + await axios.post(`${url}/book`,obj) +} + +//修改数据 +export const fetchEditData = async (id, obj) => { + await axios.put(`${url}/book/${id}`, obj) +} + +//删除数据 +export const fetchDelData = async (id) => { + await axios.delete(`${url}/book/${id}`) +} +``` +### 展示 + + diff --git "a/\345\215\242\346\200\235\346\207\277/20250521_\350\257\276\345\240\202\347\254\224\350\256\260+\344\275\234\344\270\232.md" "b/\345\215\242\346\200\235\346\207\277/20250521_\350\257\276\345\240\202\347\254\224\350\256\260+\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..dbc15578585436df956f7fda9c2be2973e2cf05d --- /dev/null +++ "b/\345\215\242\346\200\235\346\207\277/20250521_\350\257\276\345\240\202\347\254\224\350\256\260+\344\275\234\344\270\232.md" @@ -0,0 +1,21 @@ +# 笔记 +## 组件库Vant4 +#### 安装:npm install vant +#### 引入注册: +```js +import {Button} from 'vant' +app.use(Button) +``` +#### 使用: +```js + + +```