From 9dc97968bfe36457ed335ce42bb6d842652e051d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E7=8E=89=E6=95=8Fa?= <2647486093@qq.com> Date: Sun, 14 Apr 2024 23:07:25 +0800 Subject: [PATCH] node --- ...16\347\253\257\350\277\236\346\216\245.md" | 48 +++++++++++++++++++ ...72\347\241\200\344\275\277\347\224\250.md" | 9 ++++ 2 files changed, 57 insertions(+) create mode 100644 "\346\236\227\347\216\211\346\225\217/20240408_\345\211\215\345\220\216\347\253\257\350\277\236\346\216\245.md" create mode 100644 "\346\236\227\347\216\211\346\225\217/20240409_\345\237\272\347\241\200\344\275\277\347\224\250.md" diff --git "a/\346\236\227\347\216\211\346\225\217/20240408_\345\211\215\345\220\216\347\253\257\350\277\236\346\216\245.md" "b/\346\236\227\347\216\211\346\225\217/20240408_\345\211\215\345\220\216\347\253\257\350\277\236\346\216\245.md" new file mode 100644 index 0000000..6b0a6fa --- /dev/null +++ "b/\346\236\227\347\216\211\346\225\217/20240408_\345\211\215\345\220\216\347\253\257\350\277\236\346\216\245.md" @@ -0,0 +1,48 @@ +# 前端 +```html + + + +``` +```js +// +function btnDelete(id) { + if (confirm('确认删除')) { + // axios.delete(请求的url).then(res=>对res.data获取返回的数据) + axios.delete(`${config.url}/${id}`).then(res => { + // 代码块 + }) + } +} +/* +add与update1为同一个html页面,通过是否携带动态参数区分 + +此html预加载完成时,需要通过函数分解请求路径,获取params对象 +再判断动态参数是否存在 + 若存在,则为update需渲染默认数据 + 若不存在,则为add +点击提交按钮时,需要参数判断,存在调用update代码,不存在则调用add代码 +*/ +function btnSave() { + let obj = { name, price, count } + let params = getQueryString() + let id = params.id * 1 + console.log('id:', id); + if (id > 0) { + axios.put(`${config.url}/${id}`, obj).then(res => { + }) + } else { + // 发送请求,与请求数据 + axios.post('http://localhost:3000/goods', obj).then(res => { + }) + } +} +// 给location.href赋值,进行页面跳转 +function btnAdd() { + location.href = './edit.html' +} +// axios发送put/post时,如果要发送数据,则axios.post(url,data).then() +axios.post('http://localhost:3000/search', obj).then(res => { + // 代码块 +}) +``` \ No newline at end of file diff --git "a/\346\236\227\347\216\211\346\225\217/20240409_\345\237\272\347\241\200\344\275\277\347\224\250.md" "b/\346\236\227\347\216\211\346\225\217/20240409_\345\237\272\347\241\200\344\275\277\347\224\250.md" new file mode 100644 index 0000000..5865fe1 --- /dev/null +++ "b/\346\236\227\347\216\211\346\225\217/20240409_\345\237\272\347\241\200\344\275\277\347\224\250.md" @@ -0,0 +1,9 @@ +# axios使用 +res.data可以获取返回的数据 +axios.get(url).then(res=>{}) +axios.post/put(url,data) =>data发送请求数据 +# 挂载中间件 +使用async与await +app.use(async(ctx,next)=>{....await next()}) +# pgAdmin +https://baijiahao.baidu.com/s?id=1777159600925095509&wfr=spider&for=pc \ No newline at end of file -- Gitee