vue-resource对比axios import ... from和import {} from 的区别 element-ui
1.vue-resource对比axios
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 的区别
3.element-ui
vue-resource对比axios import ... from和import {} from 的区别 element-ui的更多相关文章
- vue实现多语言国际化(vue-i18n),结合element ui、vue-router、echarts以及joint等。
老板说我们的项目要和国际接轨,于是乎,加上了多语言(vue-i18n).项目用到的UI框架是element ui ,后续echarts.joint等全都得加上多语言. 一.言归正传,i18n在vue项 ...
- route按需加载的3种方式:vue异步组件、es提案的import()、webpack的require.ensure()
1. vue异步组件技术 vue-router配置路由,使用vue的异步组件技术,可以实现按需加载. 但是,这种情况下一个组件生成一个js文件.举例如下: { path: '/promisedemo' ...
- vue中的import、export、requre的区别
在es6之前js一直没有自己的模块语法,为了解决这种尴尬就有了require.js的出现.在es6发布之后js又引入了import的概念使得不清楚两者之间的区别的同学在实际使用过程中造成了自己的误解, ...
- vue中使用axios
1.结合vue-axios使用 vue-axios是按照vue插件的方式去写的,那么结合vue-axios就可以使用Vue.use()这个方法import axios from 'axios' imp ...
- vue中使用axios最详细教程
前提条件:vue-cli 项目 安装: npm npm 在main.js导入: // 引入axios,并加到原型链中 import axios from 'axios'; Vue.prototype. ...
- vue全局使用axios插件请求ajax
vue全局使用axios插件请求ajax Vue 原本有一个官方推荐的 ajax 插件 vue-resource,但是自从 Vue 更新到 2.0 之后,官方宣布停止更新vue-resource,并推 ...
- vue组件,axios ,路由
组件(Component)自定义封装的功能. 把一个功能相关的[HTML.css和javascript]代码封装在一起组成一个整体的代码块封装模式,我们称之为“组件”. 组件就是一个html网页中的功 ...
- vue创建路由,axios前后台交互,element-ui配置使用,django contentType组件
vue中创建路由 每一个vue组件都有三部分组成 template:放html代码 script:放js相关 style:放css相关 vue中创建路由 1.先创建组件 Course.vue 2.ro ...
- vue全局使用axios的方法
在vue项目开发中,我们使用axios的二次封装,很多人一开始使用axios的方式,会当成vue-resoure的使用方式来用,即在主入口文件引入import VueResource from 'vu ...
随机推荐
- LeetCode117----填充同一层兄弟节点
给定一个二叉树 struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; } 填充它的每个 ...
- oracle存储过程错误跟踪
1.首先创建用于保存错误信息的表 1 2 3 4 5 6 7 8 CREATE TABLE TBL_PROC_ERRMSG ( BIZ_CODE VARCHAR2(50), ERR_LINE ...
- 运算 Kotlin(3)
运算Kotlin支持数字运算的标准集,运算被定义为相应的类成员(但编译器会将函数调用优化为相应的指令) . 参见运算符重载.对于位运算,没有特殊字符来表示,而只可用中缀方式调用命名函数,例如:val ...
- Python 抓取数据存储到Mysql中
# -*- coding: utf-8 -*- import os,sys import requests import bs4 import pymysql#import MySQLdb #连接MY ...
- Win7、win8、win10下实现精准截获Explorer拷贝行为
介绍了windows下对Explorer的拷贝动作的精确截获,这个在企业数据安全dlp产品系列中减少审计的噪音很有效,方便运营人员做针对性的审计. 在企业数据安全中我通常需要监测用户的拷贝行为,特别像 ...
- java:Cookie(常用操作),Cookie和Session免登录实例
1.常用操作: package cn.zzsxt.lee.web.cookie; import java.io.IOException; import javax.servlet.ServletEx ...
- WebApi使用二进制方式上传和下载文件
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; usi ...
- python—004
一.集合(set) 1.定义:不同的元素组成,无序排列的,可哈希的值(存放不可变类型:数字.字符串.元组) s={1,2,'ww',3,4,5,6,7,8,'ee'}print (type(s))pr ...
- P1936 【水晶灯火灵】
lalala~~(才不会告诉你这是题面呢) 这题确实有点坑,第一遍穷举超时,然后就开始了漫漫找规律之路... 终于,在经过5分钟的纠结之后,我终于发现了这个神奇的规律,那就是 Fabonacci!!! ...
- HCL 试验1
PC端配置:配置ip地址 交换机配置:①创建VLAN system-view vlan 10 vlan 20 ②配置PC端接口 interface gi 1/0/1 port link-type ac ...