- vue打包后省略失效问题
.mult_line-ellipsis {
display: -webkit-box;
-webkit-line-clamp:2;
overflow: hidden;
/*! autoprefixer: off */
-moz-box-orient: vertical;
-webkit-box-orient: vertical;
/*! autoprefixer: on */
}
2.保存params中的列表数据
进入页面,发现params中存在数据,保存数据到localStorage,页面刷新后,params不存在则从localstorage中读取,但是这个有点冒险
- 格式化日期
formatTime: date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()
return [year, month, day].join('/') + ' ' + [hour, minute, second].join(':')
},
format: (time, format) => {
var t = new Date(time);
var tf = function (i) {
return (i < 10 ? '0' : '') + i
};
return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function (a) {
switch (a) {
case 'yyyy':
return tf(t.getFullYear());
break;
case 'MM':
return tf(t.getMonth() + 1);
break;
case 'mm':
return tf(t.getMinutes());
break;
case 'dd':
return tf(t.getDate());
break;
case 'HH':
return tf(t.getHours());
break;
case 'ss':
return tf(t.getSeconds());
break;
}
})
}
4.判断当前设备是安卓还是ios
var u = navigator.userAgent;
var isAndroid = u.indexOf("Android") > -1 || u.indexOf("Adr") > -1; //android终端
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
- 判断对象中数组的层级
//比如:
let obj = {
text: "计算机",
children: [
{
text: "软件",
children: []
},
{
text: "硬件",
children: []
}
var num = 0
_getLayer(obj, k) {
var that = this;
num = Math.max(num, k);
console.log(k);
if (obj.children && obj.children.length)
obj.children.forEach(function(v, i) {
_getLayer(v, k + 1);
});
}
_getLayer(obj,0)
6.处理不兼容isArray的情况
if (!Array.isArray) {
Array.isArray = function(arg) {
return Object.prototype.toString.call(arg) == "[object Array]";
};
- 例子同5,删除对象中空数组
// 删除空数组
function _removeEmptyArrays(data) {
for (var key in data) {
var item = data[key];
if (Array.isArray(item)) {
// 数组为空
if (item.length == 0) {
// console.log("删除空数组", item);
delete data[key];
} else if (typeof item == "object") {
// console.log("item为数组中的对象或数组", item);
_removeEmptyArrays(item);
}
} else if (typeof item == "object") {
// console.log("item为不是数组对象2", item);
_removeEmptyArrays(item);
}
}
}