GET傳遞參數(shù)要加上params
<script>
var vm=new Vue({
el:'#app',
data:{},
methods:{
get:function(){
//get請求 需要向后臺傳參數(shù) 語法:{params:{a:10,b:2}}
//this.$http.get('get.php',{params:{a:10,b:2}}).then(function(res){}
this.$http.get('get.php',{params:{a:10,b:2}}).then(function(res){
console.log(res);
console.log(res.data);
},function(res){
console.log('失敗')
})
}
}
})
</script>
POST傳遞參數(shù)方法
<script>
var vm=new Vue({
el:'#app',
data:{},
methods:{
post:function(){
//post方法有三個參數(shù)post("php文件"璧亮,"參數(shù)","emulateJSON:true")
//emulateJSON:true 模擬一個JSON數(shù)據(jù)發(fā)送到服務(wù)器沛厨,這樣才可以成功運行
this.$http.post('post.php',{a:10,b:2},{emulateJSON:true}).then(function(res){
console.log(res);
console.log(res.data);
},function(res){
console.log('失敗')
})
}
}
})
</script>
另外說一句,現(xiàn)在VUE官方推薦使用axios,例如我這種人有點懶衡创,當(dāng)初就直接用了jq的ajax代替了