【vue】vue-resource和axios

//cmd
npm vue-resource --save
 
//main.js
import VueResource from 'vue-resource'
Vue.use(VueResource)
 
//.vue
post:function(){
this.$http.post("url",{mydata})
.then(function(data){xxx});
}
 
//axios
//cmd
npm axios --axios
 
//main.js
import VueResource from 'vue-resource'
Vue.prototype.$http = axios // axios.post 变成 this.$http.post
 
//.vue
post:function(){
axios.post("url",{mydata})
.then(function(data){xxx});
}

猜你喜欢

转载自www.cnblogs.com/lovelingtaste/p/10648140.html
今日推荐