vue+axios请求头封装
import {
mapMutations
} from 'vuex'
import axios from 'axios'
import {
Toast
} from 'mint-ui';
import i18n from 'assets/js/vi18n/i18n.js'
export const mixins = {
data() {
return {
istimeout: true
}
},
methods: {
ajaxSend(urlSuffix, paramsData) {
// 公共请求数据的方法。
let vm = this;
let storage = window.localStorage;
let langCode='zh-CN';
let langChange=storage.langCode
if(langChange){
langCode=langChange;
}
let zksysReqParams = {
"lang": langCode,
"tz": "+8:00",
"agent": "zkteco",
"platform": "app",
"sys": "zks-platform",
"sessionId": storage.sessionId,
"intfVer": "1.0.0",
"payload": {
"datafmt": 1,
"params": {}
}
};
var prefixUrl = "http://192.168.12.52:8181";
// var prefixUrl = "";
// var prefixUrl=window.localStorage.prefixUrl;
storage.prefixUrl=prefixUrl;
var reqParams = Object.assign({}, zksysReqParams);
reqParams.payload.params = paramsData;
let url = prefixUrl + urlSuffix;
return axios.post(url, reqParams).then((res) => {
if (res.data.code !== '00000000') {
if (res.data.code == 'ET000001') {
// Toast('登录过期,请重新登录');
vm._chang(false); //过期的话,把show设为false。在login时进行判断。
vm.$router.push({path:'/login'});
return false;
}else{
Toast(vm.$t(res.data.code));
}
}else{
storage.sessionId=res.data.sessionId;
}
return Promise.resolve(res.data);
}).catch((err) => {
// Toast(err);
console.log(err);
})
},
getCookie: function (name) {
var cookieName = encodeURIComponent(name) + "=";
var cookieStart = document.cookie.indexOf(cookieName);
var cookieValue = null;
if (cookieStart > -1) {
var cookieEnd = document.cookie.indexOf(";", cookieStart);
if (cookieEnd == -1) {
cookieEnd = document.cookie.length;
}
cookieValue = encodeURIComponent(document.cookie.substring(cookieStart + cookieName.length, cookieEnd));
}
return decodeURIComponent(decodeURIComponent(cookieValue));
},
setCookie: function (name, value, days, path, domain, secure) {
var cookieText = encodeURIComponent(name) + "=" + encodeURIComponent(value);
if (days>0) {
var expires = new Date();
expires.setTime(expires.getTime() + days * 3600000 * 24);
//expires.setTime(expires.getTime() + days * 120000);
var _expires = (typeof days) == "string" ? "" : ";expires=" + expires.toUTCString();
cookieText = encodeURIComponent(name) + "=" + encodeURIComponent(value)+ _expires + path;
}
if (path) {
cookieText += "; path=" + path;
}
if (domain) {
cookieText += "; domain=" + domain;
}
if (secure) {
cookieText += "; secure"
}
document.cookie = cookieText;
},
unsetCookie: function (name,days, path, domain, secure) {
this.setCookie(name, "", days, path, domain, secure);
},
// 去掉多余的应该隐藏的东西。
queryTextArea() {
let list = document.querySelectorAll('textarea');
list.forEach(el => {
el.setAttribute("readonly", 'readonly');
})
let editTable = document.querySelectorAll('.editTableList');
editTable.forEach(el => {
el.style.display = 'none';
})
let spanid = document.querySelectorAll('.spanid');
spanid.forEach(el => {
el.style.display = 'none';
})
let imp_delete = document.querySelectorAll('.ipm_deletetr');
imp_delete.forEach(el => {
el.style.display = 'none';
})
let hoverx = document.querySelectorAll('.hoverx');
hoverx.forEach(el => {
el.style.display = 'none';
})
let hover = document.querySelectorAll('.hover');
hover.forEach(el => {
el.style.display = 'none';
})
let markRowStyle = document.querySelectorAll('.markRowStyle');
markRowStyle.forEach(el => {
el.style.display = 'none';
})
},
// 去拿到对应的keyList;
_getKeyList() {
let msgdata = this.$i18n.messages["zh-CN"].message;
let arr = [];
this.flagdata.forEach((el, index) => {
arr.push(el.appMenuName);
});
let keydata = [];
for (let key in msgdata) {
if (arr.indexOf(msgdata[key]) > -1) {
keydata.push(key);
}
}
this.keydata = keydata;
},
...mapMutations({
_chang: 'CHANG_SHOW'
})
},
filters: {
timerYear(value){
var oDate = new Date(value);
return oDate.getFullYear();
},
timer(value){
var oDate = new Date(value);
return oDate.getFullYear() + '/' + (oDate.getMonth() + 1 > 9 ? oDate.getMonth() + 1 : '0' + (oDate.getMonth() + 1)) + '/' + (oDate.getDate() > 9 ? oDate.getDate() : '0' + oDate.getDate());
},
timernew(value) {
var oDate = new Date(value);
return oDate.getFullYear() + '-' + (oDate.getMonth() + 1 > 9 ? oDate.getMonth() + 1 : '0' + (oDate.getMonth() + 1)) + '-' + (oDate.getDate() > 9 ? oDate.getDate() : '0' + oDate.getDate());
},
timerHen: function (input) {
var oDate = new Date(input);
return oDate.getFullYear() + '/' + (oDate.getMonth() + 1 > 9 ? oDate.getMonth() + 1 : '0' + (oDate.getMonth() + 1)) + '/' + (oDate.getDate() > 9 ? oDate.getDate() : '0' + oDate.getDate()) + ' ' + (oDate.getHours() > 9 ? oDate.getHours() : '0' + oDate.getHours()) + ':' + (oDate.getMinutes() > 9 ? oDate.getMinutes() : '0' + oDate.getMinutes());
},
timerover: function (input) {
var oDate = new Date(input);
return oDate.getFullYear() + '-' + (oDate.getMonth() + 1 > 9 ? oDate.getMonth() + 1 : '0' + (oDate.getMonth() + 1)) + '-' + (oDate.getDate() > 9 ? oDate.getDate() : '0' + oDate.getDate()) + ' ' + (oDate.getHours() > 9 ? oDate.getHours() : '0' + oDate.getHours()) + ':' + (oDate.getMinutes() > 9 ? oDate.getMinutes() : '0' + oDate.getMinutes());
},
}
}
vue+axios请求头封装的更多相关文章
- vue全局设置请求头 (封装axios请求)
Vue.http.interceptors.push((request, next) => { // 请求发送前的处理逻辑 request.headers.set('Authorization' ...
- vue/axios请求拦截
import axios from 'axios';import { Message } from 'element-ui';import Cookies from 'js-cookie';impor ...
- axios请求的封装
/* axios的请求封装 */ //axios的原生写法get,post请求 //第一个参数为请求地址,第二个参数为请求的参数,params是将参数拼接在url的后面 ...
- 10. vue axios 请求未完成时路由跳转报错问题
axios 请求未完成时路由跳转报错问题 前两天项目基本功能算是完成了,在公司测试时遇到了遇到了一个问题,那就是在请求未完成时进行路由跳转时会报错,想了几种办法来解决,例如加loading,请求拦截, ...
- axios请求头几种区别:application/x-www-form-urlencoded
今天小伙伴问我们项目axios默认请求头是application/x-www-form-urlencoded;charset=UTF-8, 现在有个后端接口要求请求头方式为application/js ...
- axios请求方法封装.
axios的使用上一般封装好对应的方法,ES6导出,直接调用,消息通知使用了ElementUI的Message组件. 这是一个封装了axios的Rest风格的工具类,包扩常用的POST,GET,PUT ...
- vue-ajax/axios请求函数封装: axios+promise
项目文件目录/src/api ajax.js /** * ajax 请求函数模块 * 返回值为promise对象 */ import axios from 'axios' export default ...
- vue axios 请求 https 的特殊处理
最近遇到自签发的CA证书,在前端axios请求https请求时,无法自动加载证书. 解决方法:将无法加载的请求在浏览器新窗口手动加载,选择继续连接. 重新加载,问题解决. 根本原因:因为自签发证书,浏 ...
- vue axios 请求本地接口端口不一致出现跨域设置代理
首先在config下面的index.js,设置跨域代理 在axios请求的时候 用'/api/' 替代baseURL 最重要的就是设置完必须重新 npm run dev 否则不生效
随机推荐
- substr 字符串截取
<!DOCTYPE html> <html> <body> <?php echo substr("Hello world",0,10).& ...
- 禁用composer update命令
composer update 命令会直接把依赖的包更新到最新,会导致整个项目代码都是没有经过测试的不稳定代码 所以一定要禁止使用该命令. 正确的做法是: 更新指定的包到指定的版本(高版本的包也可以更 ...
- maven-插件地址
Maven官方有两个插件列表, 第一个列表的GroupId 为 org.apache.maven.plugins,这里的插件最为成熟,具体地址为:http://maven.apache.org/plu ...
- mybatis 基于xml 配置的映射器
cache 给命名空间的缓存配置 cache-ref 其他命名空间缓存配置的引用 resultMap 描述如何从数据库结果集中来加载对象 <!--column不做限制,可以为任意表的字段,而p ...
- MySQL_约束条件
目录 八个约束条件 1.非空约束NOT NULL 2.主键约束PRIMARY KEY 3.多字段联合主键(复合主键) 4.唯一约束UNIQUE 5.默认约束DEFAULT 6.外键约束FOREIGN ...
- [转帖]容器云之K8s自动化安装方式的选择
容器云之K8s自动化安装方式的选择 时间 2016-12-05 19:10:53 极客头条 原文 http://geek.csdn.net/news/detail/127426 主题 Kubern ...
- [转帖] 龙芯 中标麒麟的 源 以及K8S
龙芯Mips64el平台上部署K8s https://ysicing.me/posts/mips64el-loongson-k8s/ YSICING May 29 2019 kubernetes ...
- SQL Server 验证身份证合法性函数(使用VBScript.RegExp)
原文:SQL Server 验证身份证合法性函数(使用VBScript.RegExp) 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/wzy0623 ...
- Spring注解Component原理源码解析
在实际开发中,我们经常使用Spring的@Component.@Service.@Repository以及 @Controller等注解来实现bean托管给Spring容器管理.Spring是怎么样实 ...
- selenium 鼠标,键盘操作
1.打开和关闭网页 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 #!/usr/bin/env python # -*- coding:u ...