封装vue-resource http请求
import Vue from "vue" import vueResource from "vue-resource" Vue.use(vueResource) export default{ getRequest(url,cb) { return new Promise((resolve, reject) => { Vue.http.get( url, {emulateJSON: true} ) .then(cb) .catch((err) => { reject(err); }); }); }, postRequest(url, params,cb) { return new Promise((resolve, reject) => { Vue.http.post( url, params, {emulateJSON: true} ) .then(cb) .catch((err) => { reject(err); }); }); } } import http from "http.js" //使用方法 var url = url; //url地址 var params=params; http.postRequest(url, params,(res)=>{ console.log(res) })