$doAjaxV2的实现代码如下:
//对ajax进行一个封装 var doAjaxV2= function(action,param,callback,bAsync=true,bLoading=false){ //发起ajax请求后台数据 var _this = this; //这里的this 在ajax中会被改变 if(bLoading) { _this.ajaxloading = _this.$loading("正在处理中..."); } jQuery.ajax({ type:'POST', url:action, data:param, async: bAsync, //如果使用异步操作,会出现内容加载错误的bug,目前不明白如何处理 dataType: "json", success:function(data) { if(bLoading) { _this.ajaxloading.close(); } if(data.err.code!=0) //有错误发生 { _this.$message.error(data.err.msg); return false; } else { callback(data.data); } }, error:function() { if(bLoading) { _this.ajaxloading.close(); } _this.$message.error("ajax操作失败"); } }); } Vue.prototype.$doAjaxV2 = doAjaxV2; //将方法放在原型上。
1,在Vue中增加了对jquery的调用
2,实现了doAjaxV2方法
更多详情>>
暂无数据
评论 (0)