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 否则不生效
随机推荐
- 利用phpStudy 探针 提权网站服务器
声明: 本教程仅仅是演示管理员安全意识不强,存在弱口令情况.网站被非法入侵的演示,请勿用于恶意用途! 今天看到论坛有人发布了一个通过这phpStudy 探针 关键字搜索检索提权网址服务器,这个挺简单的 ...
- [CDH] Cloudera's Distribution including Apache Hadoop
You may choose to install spark, yarn, hive, etc one by one. [Spark] 00 - Install Hadoop & Spark ...
- Scala面向对象03
- Swift 3.0 Date的简单使用
// // ViewController.swift // Date的使用 // // Created by 思 彭 on 16/9/20. // Copyright © 2016年 思 彭. All ...
- JavaScript高程第三版笔记-DOM扩展
在那个刀耕火种的年代,用过jQuery的都体会到了jQuery带来的便捷,尤其是元素选择器. jQuery(www.jquery.com)的核心就是通过 CSS 选择符查询 DOM 文档取得元素的引用 ...
- 测试ssh转发
端口转发提供: 1.加密 SSH Client 端至 SSH Server 端之间的通讯数据. 2.突破防火墙的限制完成一些之前无法建立的 TCP 连接. 但是只能转发tcp连接,想要转发UDP,需要 ...
- PHP非对称加密
加密的类型: 在日常设计及开发中,为确保数据传输和数据存储的安全,可通过特定的算法,将数据明文加密成复杂的密文.目前主流加密手段大致可分为单向加密和双向加密. 单向加密:通过对数据进行摘要计算生成密文 ...
- 【计算机视觉】Histogram of Oriented Gridients(HOG) 方向梯度直方图
Histogram of Oriented Gridients(HOG) 方向梯度直方图 Histogram of Oriented Gridients,缩写为HOG,是目前计算机视觉.模式识别领域很 ...
- Vue-cli3性能优化
Vue-cli3.0的打包性能优化方案:https://juejin.im/post/5d42962be51d4561b84c00c3 提升90%加载速度——vuecli下的首屏性能优化:https: ...
- mapreducer计算原理
mapreducer计算原理