加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Vue开发中整合axios的文件整理

发布时间:2020-12-17 02:59:00 所属栏目:百科 来源:网络整理
导读:前言 大家在vue日常开发中,不可避免要整合axios,这里简单记录一下整合中的文件,方便以后使用查找。下面来看看详细的介绍。 整合方法 整合文件axios.js {//Serialize.decode(config);return config;});instance.interceptors.response.use(response=> {ret

前言

大家在vue日常开发中,不可避免要整合axios,这里简单记录一下整合中的文件,方便以后使用查找。下面来看看详细的介绍。

整合方法

整合文件axios.js

{ //Serialize.decode(config); return config; }); instance.interceptors.response.use(response=> { return response.data; },err=> { if (err.response) { axios.post('/v1/error',err.response); return Promise.reject(err.response.data); } return Promise.reject({ code: 1024,message: err.message }); }); function plugin(Vue) { if (plugin.installed) { return; } Vue.http = instance; } if (typeof window !== 'undefined' && window.Vue) { window.Vue.use(plugin); } export default plugin;

vue插件使用 app.js

{ Vue.filter(key,filters[key]); }); // create the app instance. // here we inject the router and store to all child components,// making them available everywhere as `this.$router` and `this.$store`. const app = new Vue({ router,store,...App }); // expose the app,the router and the store. // note we not mounting the app here,since bootstrapping will be // different depending on whether we are in browser or on the server. export { app,router,store };

在vuex action 中使用:

{ ctx.commit(TypesAds.AD_GET_LIST,data); return data; }).catch(err=> { //统一错误处理 Vue.$message.error(err.msg); }); } }

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对编程之家的支持。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读