1.vue-resource对比axios

文章1

文章2

1.0 axios  params 配置参数在url 显示,form-data 用于 图片上传、文件上传

1.1 axios 全局配置

axios.defaults.baseURL=‘http:localhost:8080’

1.2 axios 实例配置

let instance=axios.create()

instance.defaults.timeout=3000

或者

let instance=axios.create({

timeout:3000
})

instance.get('data/json',{

params:{id:1}

}).then(

(res)=>{

console.log(res)

})

1.3 axios 请求配置

instance.get('/data.json',{

timeout:3000

})

1.4 拦截器

1.4.1 请求拦截器

axios.interceptors.request.use(

config=>{ return config },

err=>{ return Promise.reject(err) }

)

1.4.2 响应拦截器

axios.interceptors.response.use(

res=>{ return res },

err=>{ return Promise.reject(err) }

)

1.4.3 取消拦截器

axios.interceptors.response.eject(interceptors)

1.4.4 实际例子 :登录权限

let instance=axios.create({})

instance.interceptors.request.use(

config=>{

//$('load').show()

config.headers.token='';

return config

}

)

1.5 取消请求

let source=axios.CancleTaken.source();

axios.get('/list',{

CancleTaken:source.token

}).then().catch()

取消(场景:查询结果时间过长)

source.cancle('mes')

扩展:

扩展 1.  post delete put get  常用写法

// 增删改查 post\delete\put(patch:part change)\get
// 1.get // axios.get('/data.json').then(res=>{
// console.log(res);
// }) // axios.get('/data.json',{
// params:{
// id:100
// }
// }).then(res=>{
// console.log(res);
// }) // axios({
// url:'/data.json',
// method:'get',
// params:{
// id:200
// }
// }).then(res=>{
// console.log(res);
// }) // 2.post
// form-data 表单提交:图片、文件上传
// application/json // axios.post('/data',{
// arr:[1,2]
// }).then(res=>{
// console.log(res);
// }) // axios({//get error way - query string parameters
// url:'/data',
// method:'post',
// params:{
// arr:[3,4]
// }
// }).then(res=>{
// console.log(res);
// }) // axios({ // request payload content-type: application/json
// url:'/data',
// method:'post',
// data:{
// arr:[3,4]
// }
// }).then(res=>{
// console.log(res);
// }) let data = {
id:300
};
let myform = new FormData();
for(let key in data){
myform.append(key,data[key])
} // axios({ // content-type: multipart/form-data
// url:'/data',
// method:'post',
// data:myform
// }).then(res=>{
// console.log(res);
// }) axios.post('/data',myform).then(res=>{
console.log(res);
})

扩展 2. 并发请求

    axios.all([
axios.get('/data.json'),
axios.get('/data.json')
]).then(
axios.spread((res1,res2)=>{
console.log(res1,res2);
})
)

2. import ... from和import {} from 的区别

文章1

文章2 简版

3.element-ui

Vue + ElementUI 手撸后台管理网站

Vue+ElementUI从零开始搭建自己的网站

vue-resource对比axios import ... from和import {} from 的区别 element-ui的更多相关文章

  1. vue实现多语言国际化(vue-i18n),结合element ui、vue-router、echarts以及joint等。

    老板说我们的项目要和国际接轨,于是乎,加上了多语言(vue-i18n).项目用到的UI框架是element ui ,后续echarts.joint等全都得加上多语言. 一.言归正传,i18n在vue项 ...

  2. route按需加载的3种方式:vue异步组件、es提案的import()、webpack的require.ensure()

    1. vue异步组件技术 vue-router配置路由,使用vue的异步组件技术,可以实现按需加载. 但是,这种情况下一个组件生成一个js文件.举例如下: { path: '/promisedemo' ...

  3. vue中的import、export、requre的区别

    在es6之前js一直没有自己的模块语法,为了解决这种尴尬就有了require.js的出现.在es6发布之后js又引入了import的概念使得不清楚两者之间的区别的同学在实际使用过程中造成了自己的误解, ...

  4. vue中使用axios

    1.结合vue-axios使用 vue-axios是按照vue插件的方式去写的,那么结合vue-axios就可以使用Vue.use()这个方法import axios from 'axios' imp ...

  5. vue中使用axios最详细教程

    前提条件:vue-cli 项目 安装: npm npm 在main.js导入: // 引入axios,并加到原型链中 import axios from 'axios'; Vue.prototype. ...

  6. vue全局使用axios插件请求ajax

    vue全局使用axios插件请求ajax Vue 原本有一个官方推荐的 ajax 插件 vue-resource,但是自从 Vue 更新到 2.0 之后,官方宣布停止更新vue-resource,并推 ...

  7. vue组件,axios ,路由

    组件(Component)自定义封装的功能. 把一个功能相关的[HTML.css和javascript]代码封装在一起组成一个整体的代码块封装模式,我们称之为“组件”. 组件就是一个html网页中的功 ...

  8. vue创建路由,axios前后台交互,element-ui配置使用,django contentType组件

    vue中创建路由 每一个vue组件都有三部分组成 template:放html代码 script:放js相关 style:放css相关 vue中创建路由 1.先创建组件 Course.vue 2.ro ...

  9. vue全局使用axios的方法

    在vue项目开发中,我们使用axios的二次封装,很多人一开始使用axios的方式,会当成vue-resoure的使用方式来用,即在主入口文件引入import VueResource from 'vu ...

随机推荐

  1. shiro所需的依赖

    <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-spring< ...

  2. hibernate entitymanager的理解

    hibernate EntityManager是围绕提供JPA编程接口的Hibernate Core的一个包装,支持JPA实体实例的生命周期,并允许你用标准的JavaPersistence查询语言编写 ...

  3. SSM三大框架整合配置详解

    首先,导入框架所需要的全部jar包(此处省略...........) 第一步:先从mybatis框架开始 我们只需要在mybatis的核心配置文件sqlConfigXml里写上这么一段话,代表的是给p ...

  4. LVM创建过程

    磁盘挂载需求/cachesys 50G /journal 300G /wij 50G /dthealth 20G /data 500G /backup 500G #第1步,创建pv,并查状态信息.ls ...

  5. RF Setup和Teardown的使用

    执行顺序 setup执行顺序是:project级别setup>suite级别setup>case级别setup 无返回值 Run Keywords | [KW1 | arg1 | arg2 ...

  6. idea 导入 open项目

    导入  import Project 选择你的项目目录 (位置可以直接是svn下下来的项目目录 不用新建空项目或者目录) 如果有提示直接yes  没有拉到 一路next 如果提示  覆盖就ok (一路 ...

  7. 阶段3 2.Spring_01.Spring框架简介_01.spring课程四天安排

    spring共四天 第一天:spring框架的概述以及spring中基于XML的IOC配置 第二天:spring中基于注解的IOC和ioc的案例 第三天:spring中的aop和基于XML以及注解的A ...

  8. 216组合总和III

    题目:找出所有相加之和为 n 的 k 个数的组合.组合中只允许含有 1 - 9 的正整数,并且每种组合中不存在重复的数字.说明:所有数字都是正整数.解集不能包含重复的组合. 示例 1:输入: k = ...

  9. springmvc请求参数获取(自动绑定)的几种方法

    1.直接把表单的参数写在Controller相应的方法的形参中,适用于get方式提交,不适用于post方式提交. /** * 1.直接把表单的参数写在Controller相应的方法的形参中 * @pa ...

  10. python__005

    一.字符串格式化 #字符串的拼接#msg='i am a best boy'+'非常帅'print(msg)name=input('name:')hobby=input(('hobby:'))age= ...