12.28

复盘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的同时进行相关项目的学习实操 加强练习 

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值