复盘node.js部分项目
1.初始化包管理配置文件 用来检测安装的第三方包的相关信息
2.使用npm i 安装所需要的第三方包 指定版本
3.配置入口文件app.js 启动服务器
4.配置路由模块(单纯的对应关系)(router.js)
5.抽离路由函数关系模块(router_handler.js)
6.创建与数据库的联系的文件(index.js)
7.验证规则文件(user.js)
8.单独定义密匙文件(config.js)
9.在入口文件引入所需的全局中间件
10.优化重复代码 定义全局中间件封装函数
11.注意配置中间件时的顺序问题 错误中间件在路由之后
复盘axios部分
1.使用json-server快速搭建一个假的服务器
2.复盘具体写法
<button>GET</button>
<button>POST</button>
<button>PUT</button>
<button>DELETE</button>
<script>
const btns=document.querySelectorAll('button')
btns[0].onclick=function(){
axios({
method:'GET',
url:'http://localhost:3000/posts/2',
}).then((response)=>{
console.log(response)
})
}
//往db.json里面添加数据
btns[1].onclick=function(){
axios({
method:'POST',
url:'http://localhost:3000/posts',//这里没有具体id
//请求体
data:{
title:'天气'
}
}).then((response)=>{
console.log(response)
})
}
//更新数据
btns[2].onclick=function(){
axios({
method:'PUT',
url:'http://localhost:3000/posts/3',
data:{
title:'季节'
}
}).then((response)=>{
console.log(response)
})
}
//删除数据
btns[3].onclick=function(){
axios({
method:'DELETE',
url:'http://localhost:3000/posts/6'
})
}
</script>
3,默认配置
axios.defaults.method='GET'
axios.defaults.baseURL='http://localhost:3000'
axios.defaults.params={id:100}//url参数
axios.defaults.timeout=3000 //三秒钟结果未返回取消请求
btns[0].onclick=function(){
axios({
url:'posts',
}).then((response)=>{
console.log(response)
})
}
4.拦截器以及取消请求
接下来在复习vue的同时进行相关项目的学习实操 加强练习