VUE中 axios GET和POST 如何使用


axios作用:Axios 是一個基於 promise 的 HTTP 庫,可以用在瀏覽器和 node.js 中。

  首先。安裝及配置

    使用npm安裝 

      npm install axios

    使用 yarn 安裝

      yarn add axios

  然后在入口文件 main.js中引入

     import axios from 'axios'

     vue.prototype.$axios = axios

axios POST請求實例

      that.$axios.post(url,{a:1,b:2})
      .then(function (res) {
         console.log("返回值")
      })
      .catch(function (error) {
        console.log(error);
      });

 

axios get請求實例

       this.$axios.get(url,{params:{a:1,b:2}})
      .then(function (response) {
         console.log('返回值')
      })
      .catch(function (error) {
        //  this.$message.error(error);
      });

  

 

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM