源代碼
點擊運行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Vue 測試實例 - 教程</title> <script src="https://cdn.staticfile.org/vue/2.4.2/vue.min.js"></script> <script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"></script> </head> <body> <div id="box"> <input type="button" @click="post()" value="點我異步獲取數據(Post)"> </div> <script type = "text/javascript"> window.onload = function(){ var vm = new Vue({ el:'#box', data:{ msg:'Hello World!', }, methods:{ post:function(){ //發送 post 請求 this.$http.post('/try/ajax/demo_test_post.asp',{name:"教程",url:"http://www.sharebody.com"},{emulateJSON:true}).then(function(res){ document.write(res.body); },function(res){ console.log(res.status); }); } } }); } </script> </body> </html>
運行結果