• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >JavaScript > Vue开发中整合axios的文件整理

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

作者:彬仔 字体:[增加 减小] 来源:互联网 时间:2017-05-11

彬仔通过本文主要向大家介绍了vue axios,vue.js axios,vue axios 跨域,vue2.0 axios,vue中使用axios等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

前言

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

整合方法

整合文件axios.js

import axios from 'axios';
// 适配vue-resource
const instance = axios.create();
instance.interceptors.request.use(config=> {
//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;
</div>

vue插件使用 app.js

import Vue from 'vue';
import App from './App.vue';
import store from './store';
import { sync } from 'vuex-router-sync';
import router from './router';
import * as filters from './filters';
import yxui from 'yxui/dist/yxui.min';
import axios from './axios';
Vue.use(yxui);
Vue.use(axios);
// sync the router with the vuex store.
// this registers `store.state.route`
sync(store, router);
// register global utility filters.
Object.keys(filters).forEach(key => {
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 };
</div>

在vuex action 中使用:

actions: {
// adList
[TypesAds.AD_GET_LIST](ctx, params){
return Vue.http.get('/v1/api/ads/list', {params}).then(data=> {
ctx.commit(TypesAds.AD_GET_LIST, data);
return data;
}).catch(err=> {
//统一错误处理
Vue.$message.error(err.msg);
});
}
}
</div>

总结

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

</div>
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • Vue开发中整合axios的文件整理
  • Vue+axios 实现http拦截及路由拦截实例
  • 详解Vue.js 2.0 如何使用axios
  • 关于axios返回空对象的问题解决

相关文章

  • 2017-05-11JavaScript表单验证的两种实现方法
  • 2017-05-11jQuery EasyUi 验证功能实例解析
  • 2017-05-11jQuery基于正则表达式的表单验证功能示例
  • 2017-05-11微信小程序 textarea 组件详解及简单实例
  • 2017-05-11jQuery图片拖动组件Dropzone用法示例
  • 2017-05-11详解vue.js全局组件和局部组件
  • 2017-05-11JavaScript利用闭包实现模块化
  • 2017-05-11原生JS实现几个常用DOM操作API实例
  • 2017-05-11jQuery插件HighCharts实现2D柱状图、折线图的组合多轴图效果示例【附demo源码下载】
  • 2017-05-11JQuery异步提交表单与文件上传功能示例

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • 微信小程序 chooseImage选择图片或者拍照
    • jQuery UI仿淘宝搜索下拉列表功能
    • jQuery使用unlock.js插件实现滑动解锁
    • vue-resourse将json数据输出实例
    • 移动端web滚动分页的实现方法
    • ionic2打包android时gradle无法下载的解决方法
    • JS表格组件神器bootstrap table使用指南详解
    • bootstrap表单按回车会自动刷新页面的解决办法
    • 利用js判断手机是否安装某个app的多种方案
    • JavaScript中利用构造器函数模拟类的方法

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有