• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com专业计算机教程网站
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • html/xhtml
  • html5
  • CSS
  • XML/XSLT
  • Dreamweaver教程
  • Frontpage教程
  • 心得技巧
  • bootstrap
  • vue
  • AngularJS
  • HBuilder教程
  • css3
  • 浏览器兼容
  • div/css
  • 网页编辑器
  • axure
您的位置:首页 > 网页设计 >vue > Vue开发中整合axios的文件整理

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

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

本文主要包含vue axios,vue axios 跨域,vue.js axios,vue2.0 axios,vue中使用axios等相关知识,彬仔 希望在学习及工作中可以帮助到您

前言

大家在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>

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

  • vue+axios实现登录拦截的实例代码
  • 详解Vue用axios发送post请求自动set cookie
  • VUE 更好的 ajax 上传处理 axios.js实现代码
  • 详解axios在vue中的简单配置与使用
  • Vue开发中整合axios的文件整理
  • Vue+axios 实现http拦截及路由拦截实例
  • 详解Vue.js 2.0 如何使用axios

相关文章

  • 2017-05-30Vue.js第二天学习笔记(vue-router)
  • 2017-05-30Vuejs第十二篇之动态组件全面解析
  • 2017-05-30Vue2单一事件管理组件通信
  • 2017-05-30Vue中添加过渡效果的方法
  • 2017-05-30vue多级多选菜单组件开发
  • 2017-05-30Vue实现动态显示textarea剩余字数
  • 2017-05-30从0开始学Vue
  • 2017-05-30Vue 2.0 服务端渲染入门介绍
  • 2017-05-30Vue自定义指令拖拽功能示例
  • 2017-05-30vue中渐进过渡效果实现

文章分类

  • html/xhtml
  • html5
  • CSS
  • XML/XSLT
  • Dreamweaver教程
  • Frontpage教程
  • 心得技巧
  • bootstrap
  • vue
  • AngularJS
  • HBuilder教程
  • css3
  • 浏览器兼容
  • div/css
  • 网页编辑器
  • axure

最近更新的内容

    • 深入理解vue路由的使用
    • 详解使用vue脚手架工具搭建vue-webpack项目
    • Vue UI组件 开发框架 服务端 辅助工具 应用实例 Demo示例
    • vue学习笔记之指令v-text && v-html && v-bind详解
    • Vue.js 2.0 移动端拍照压缩图片预览及上传实例
    • 自带气泡提示的vue校验插件(vue-verify-pop)
    • 简单理解vue中实例属性vm.$els
    • vue之nextTick全面解析
    • 详解在Vue中通过自定义指令获取dom元素
    • vue图片加载与显示默认图片实例代码

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

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