1:时间字符串转换
{{val.substring(0,10)}}
“2020-07-08 00:00:00” 显示为 2020-07-08
{{(val.substring(0,10)).replace(/-/g, ‘.’)}}
“2020-07-08 00:00:00” 显示为 2020.07.08
___________________________________________________
2:截取小数点后两位
{{scope.row.amt|numFilter}}万元
filters: {
numFilter (value) {
// 截取当前数据到小数点后两位
let realVal = parseFloat(value).toFixed(2)
return realVal
}
}
___________________________________________________
3.删除重复项
const removeDuplicates = (arr) => [...new Set(arr)];
console.log(removeDuplicates([1, 2, 3, 3, 4, 4, 5, 5, 6]));
// Result: [ 1, 2, 3, 4, 5, 6 ]
___________________________________________________
4.检查数组是否为空
const isNotEmpty = arr => Array.isArray(arr) && arr.length > 0;
isNotEmpty([1, 2, 3]);
// Result: true
__________________________________________________
5.嵌套导致下拉框的冒泡事件
:popper-append-to-body="false"
__________________________________________________
6.el-popover自适应位置
:fallback-placements="['bottom', 'top', 'right', 'left']"
__________________________________________________
7.对象转换成数组
比如说 const categoryProp = {食品:34,家居生活:23,运动户外:12}
转换成 [{name:食品,value:34},{name:家居生活,value:23},{name:运动户外,value:12}]的形式
//以下代码
const categoryPropXData = Object.keys(categoryProp || {});
const categoryPropYData = Object.values(categoryProp || {});
const newDataArr = [];
categoryPropXData.map((item, index) => {
newDataArr.push({
name: item,
value: categoryPropYData[index],
});
});
__________________________________________________
8.强制更新dom元素
this.$nextTick(() => {
this.xxxx
……
})
__________________________________________________
9.深拷贝
JSON.parse(JSON.stringify(this.xxxxx))
__________________________________________________
10.转成json串
JSON.stringify(Array)
__________________________________________________