axios

104 阅读1分钟

vue的axios

首先在终端内输入npm install axios

然后npm i axios –D转开发

要注意在全面配置中get传参数要使用params 不要使用data

第一种方式 axios.get('cnodejs.org/api/v1/topi…')

 .then(res=>{
   console.log(res.data);
})


 第二种方式 
 
 
 axios.get('https://cnodejs.org/api/v1/topics',{
   params:{
     name:'zhangsan'
   }
 })
 .then(res=>{
   console.log(res.data);
 })

/* post请求 */
// axios.post('https://api.shop.eduwork.cn/api/auth/login',{
//   email:"super@a.com",
//   password:"123123"
// })
// .then(res=>{
//   console.log(res);
// })
// .catch(err=>{
//   console.log(err);
// })
/* 使用全面配置的方式 发送post请求 */
axios({
  method:"post",
  url:"http://timemeetyou.com:8889/api/private/v1/users",
  headers:{
    "Authorization":'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjUwMCwicmlkIjowLCJpYXQiOjE1MTI1NDQyOTksImV4cCI6MTUxMjYzMDY5OX0.eGrsrvwHm-tPsO9r_pxHIQ5i5L1kX9RX444uwnRGaIM'
  },
  params:{
  pagenum:1,
  pagesize:10
  }
}

)
.then(res=>{
  console.log(res);
})
.catch(err=>{
  console.log(err);
})