axios的基本使用

170 阅读1分钟

执行get请求简写

npm i axios 下载
axios.get('地址')
    .then((res)=>{
      console.log(res);
    })

可选址,也可以这样写

axios
      .get("地址", {
        params: {
          pagenum: 1,
          pagesize: 10,
        },
        headers: {
          Authorization:
            "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjUwMCwicmlkIjowLCJpYXQiOjE1MTI1NDQyOTksImV4cCI6MTUxMjYzMDY5OX0.eGrsrvwHm-tPsO9r_pxHIQ5i5L1kX9RX444uwnRGaIM",
        },
      })
      .then((res) => {
        console.log(res);
      })
      .catch((err) => {
        console.log(err);
      });

执行post请求

  axios.post('地址',{
      username: "zhangsan",
      password: "123456",
    })
    .then((res)=>{
      console.log(res);
    })
    .catch((err)=>{
      console.log(err);
    }) 

兄弟组件通信

在js里面将vue的实例化对象给$bus

image.png

在一个组件内使用$on接受,v就是传过来的值

image.png

在另一个组件内传值

image.png