没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
vue接口请求加密实例接口请求加密实例
主要介绍了vue接口请求加密实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
1. 安装vue项目 npm init webpack project
2 安装iview npm i iview --save (这里是结合iview框架使用的 可根据自己的需求安装 当然也可以不安装)
3 在src目录下建一个utils文件夹 里面需要放5个js 都是封装好的js文件 功能不仅仅局限于加密 可以研究一下 你会学到很多东
西
1.api.js
/**
* 为vue实例添加http方法
* Vue.use(http)
*/
import http from './http'
export default {
/**
* install钩子
* @param {Vue} Vue Vue
*/
install (Vue) {
Vue.prototype.http = http
}
}
2. filters.js
// 公共使用的filters
import Vue from 'vue';
import {getTime, getPrdType} from '../utils/time';
// 区分支付方式的filter
Vue.filter('paywayType', function (value) {
return value;
});
// 时间
Vue.filter('newdate', function (value) {
return getTime(value);
});
// 时间-分钟
Vue.filter('minute', function (str, n) {
const num = parseInt(n);
return str.split(' ')[num];
});
// 分割以:连接多个参数的string
Vue.filter('valStr', function (str, n) {
const num = parseInt(n);
return str.split(':')[num];
});
// 根据提供时间计算倒计时
Vue.filter('countDown', function (str) {
const dateStr = new Date(str).getTime();
const timeNow = new Date().getTime();
const countDown = dateStr - timeNow;
const countDownDay = Math.floor((dateStr - timeNow) / 86400000);// 计算剩余天数
const countDownHour = Math.floor((dateStr - timeNow) / 3600000 % 24);// 计算剩余小时
const countDownMin = Math.floor((dateStr - timeNow) / 60000 % 60);// 计算剩余分钟
// const countDownSec = Math.floor((dateStr - timeNow) / 1000 % 60);// 计算剩余秒
if (countDown <= 0) {
return '- - - -';
} else {
return countDownDay + '天' + countDownHour + '小时' + countDownMin + '分钟';
}
});
// 取绝对值
Vue.filter('numberFn', function (numberStr) {
return Math.abs(numberStr);
});
// 处理图片地址的filter
Vue.filter('imgSrc', function (src) {
const env = getPrdType();
switch (env) {
资源评论
weixin_38674512
- 粉丝: 0
- 资源: 889
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功