vue-resource 發起get、post請求


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./node_modules/vue/dist/vue.js"></script>
    <script src="./node_modules/vue-resource/dist/vue-resource.js"></script>
    <!--路徑為本地路徑-->
</head>
<body>
    <div id="app"></div>
    <script>
       var vm = new Vue({    // 創建新的 vue 實例
           el = "#app",      // 獲取id
           data = {},        // 數據對象
           // 發起請求
           getInfo () { // 發起 get 請求
            this.$http.get(url, {params: {JSONdata} }.then(function(result){
                 console.log(result) 
                 console.log(result.body)// 通過 result.body 拿到服務器返回內容
               })) 
             },
           postInfo () {
                  // 第一個是地址,第二個是提交數據,第三個是格式 為普通表單
                  this.$http.post('url', {}, {emulateJSON: true}).then( 
                      result=>{
                          console.log(result.body)
                      }
                  )
              },
        })
    </script>

</body>
</html>


免責聲明!

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



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