axios
作者:互联网
json-server
安装:
npm install -g json-server
运行:
json-server --watch db.json
axios函数
method:get 获取、post 添加、put 更新、delete 删除
// 获取 get btns[0].addEventListener("click", () => { axios({ method: "GET", url: "http://localhost:3000/posts/2", }).then((response) => { console.log(response); }); }); // 添加 post btns[1].addEventListener("click", () => { axios({ method: "POST", url: "http://localhost:3000/posts", data: { title: "时间控制大师", auther: "rql", }, }).then((response) => { console.log(response); console.log("请求成功"); }); }); // 更新 put btns[2].addEventListener("click", () => { axios({ method: "PUT", url: "http://localhost:3000/posts/3", data: { title: "时间控制大师", auther: "任青龙", }, }).then((response) => { console.log(response); console.log("请求成功"); }); }); // 删除 delete btns[3].addEventListener("click", () => { axios({ method: "DELETE", url: "http://localhost:3000/posts/3", }).then((response) => { console.log(response); console.log("请求成功"); }); });
标签:axios,console,log,response,3000,method 来源: https://www.cnblogs.com/i269/p/16667209.html