添加请求失败默认处理函数

pull/1/head
Doflatango 2017-03-10 11:58:06 +08:00 committed by miraclesu
parent 4f7a6625ee
commit 01b4ba5d6b
3 changed files with 7 additions and 3 deletions

View File

@ -158,7 +158,7 @@ export default {
} }
} }
}). }).
onfailed((data)=>{vm.error = data.error}). onfailed((msg)=>{vm.error = msg}).
do(); do();
} }

View File

@ -3,7 +3,7 @@ var sendXHR = function(opt) {
xhr.open(opt.method, opt.url, true); xhr.open(opt.method, opt.url, true);
if (typeof opt.onexception == 'function') { if (typeof opt.onexception == 'function') {
var warpExceptionHandler = ()=>{ var warpExceptionHandler = (msg)=>{
opt.onexception(msg); opt.onexception(msg);
typeof opt.onend == 'function' && opt.onend(xhr); typeof opt.onend == 'function' && opt.onend(xhr);
} }

View File

@ -14,8 +14,9 @@ const RestApi = (Vue, options)=>{
Vue.use(RestApi); Vue.use(RestApi);
// global event bus // global event bus
var bus = new Vue();
Vue.use((Vue)=>{ Vue.use((Vue)=>{
Vue.prototype.$bus = new Vue(); Vue.prototype.$bus = bus;
}); });
import VueRouter from 'vue-router'; import VueRouter from 'vue-router';
@ -57,6 +58,9 @@ restApi.GET('configurations').onsucceed(200, (resp)=>{
} }
Vue.use(Config); Vue.use(Config);
restApi.defaultExceptionHandler = (msg)=>{bus.$emit('error', msg)};
restApi.defaultFailedHandler = (msg)=>{bus.$emit('error', msg)};
var app = new Vue({ var app = new Vue({
el: '#app', el: '#app',
render: h => h(App), render: h => h(App),