axios發送ajax請求


安裝:

npm install axios --save

package.json

如圖所示,安裝成功。

在main.js中配置

axios發送請求

mounted:function () {
      //vue頁面加載時自動執行
      this.initCourse()
    },
    methods:{
      initCourse:function () {
        var that=this
        //通過ajax向接口發送請求,並獲取課程列表
        //axios發送ajax請求
        //npm install axios --save
        //第一步:在main.js中配置
        //第二步:使用axios發送請求
        this.$axios.request({
          url:'http://127.0.0.1:8000/luffy/v1/course/',
          method:'GET'
        }).then(function (ret) {
          //ajax請求發送成功后,獲取的相應內容
            if(ret.data.code===1000){
              that.CourseList=ret.data.data
            }else{
              alert("獲取數據失敗")
            }
        }).catch(function (ret) {
          //ajax請求失敗之后,獲取相應的內容

        })
      }

   


免責聲明!

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



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