- placeholder的国际化
<input :placeholder="$t('file.search')">
- 查看对象的键和值
1 Object.keys(this.showAddMember) // 查看this.showAddMember的键 2 Object.values(this.showAddMember)// 查看this.showAddMember的值 3 this.showAddMember = { 4 contact:Object 5 4339810:Object(......) 6 4339811:Object(......) 7 }
- 数组包含的用法
let site = ['runoob', 'google', 'taobao']; site.includes('runoob'); // true site.includes('baidu');// false
- 数组去重
Array.from(new Set(serverList))
- 删除文件的工具(比如删除node_modules)
npm install ramraf -g (安装) rimraf node_modules (指令) tip:node_modules是要删除的文件或文件夹,按tab有文件名称补全功能
- 超出部分显示.....
overflow: hidden; // 超出部分隐藏 text-overflow: ellipsis; // 超出部分显示省略号 white-space: nowrap; // 规定段落中的文本不进行换行 width: 100px; //需要配合宽度来使用,否则无效
- 超出部分,多行,显示.....
width: 500px; overflow: hidden; text-overflow: ellipsis; display:-webkit-box; -webkit-line-clamp:3; -webkit-box-orient:vertical;
- 鼠标挪到下拉内容中,显示右侧滚轮
overflow:overlay;
- 将数组内的对象进行排序
var presonArr = [ { name:'freddy', age:24, score:97 }, { name:'nick', age:18, score:87 }, { name:'mike', age:26, score:80 }, { name:'james', age:34, score:90 }, { name:'curry', age:30, score:83 } ]; presonArr.sort(function(a,b){ return a.age - b.age; }); console.log(presonArr);
- Json转对象
JSON.parse() var jsonStr = '{"key":"value"}'; //只能转换jsonStr这种 var jsonStr1 = '{key:"value"}'; console.log(JSON.parse(jsonStr)); // 结果:{key: "value"} console.log(JSON.parse(jsonStr1)); // 结果:Unexpected token k in JSON at position 1 at JSON.parse (<anonymous>) 2.eval() var jsonStr = '{"key":"value"}'; var jsonStr1 = '{key:"value"}'; console.log(eval('(' + jsonStr + ')')); // 结果:{key: "value"} console.log(eval('(' + jsonStr1 + ')')); // 结果:{key: "value"}
- 时间戳转换
console.log(new Date().getTime())
- 写一个杀进程的.bat文件(杀node为例)
taskkill /im node.exe /f
- 计算文件大小
computedFileSize(preSize) { // 计算文件大小 const unitArr = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; let index = 0; const srcsize = parseFloat(preSize); index = Math.floor(Math.log(srcsize) / Math.log(1024)); let size = srcsize / 1024 ** index; size = size.toFixed(1); return size + unitArr[index]; },