```
8. vue中拖拽
+ 1. `cnpm i vuedraggable -S`
+ 2. `https://github.com/SortableJS/Vue.Draggable`
9. 同级div设置display:inline-block,父级div强制不换行
```html
测试测试
测试测试
测试测试
测试测试
测试测试
```
10. vue中自定义指令
```
Vue.directive('foucs', {
inserted: function(el, binding, vnode, oldVnode) {
el.focus();
}
})
```
11. echarts的tooltip自动播放
参考地址:https://blog.csdn.net/LZY_1993/article/details/78630805
12. el-scrollbar的滚动事件监听
https://www.cnblogs.com/lwlblog/p/13283681.html
13. vue-treeselect
cnpm install --save @riophae/vue-treeselect
14. 自定义过滤器
```js
filters: {
transformTime (val) {
if (!val) return '';
let date = new Date(val);
let y = date.getFullYear();
let m = date.getMonth() + 1;
let d = date.getDate();
let h = date.getHours();
let minute = date.getMinutes();
d = d < 10 ? ('0' + d) : d;
h = h < 10 ? ('0' + h) : h;
m = m < 10 ? ('0' + m) : m;
minute = minute < 10 ? ('0' + minute) : minute;
return `${y}-${m}-${d} ${h}:${minute}`;
}
}
```
15. vue自带的打包报告 `npm run build -- --report`
16. 深拷贝
```js
export const deepClone = obj => {
//判断拷贝的要进行深拷贝的是数组还是对象,是数组的话进行数组拷贝,对象的话进行对象拷贝
var objClone = Array.isArray(obj) ? [] : {};
//进行深拷贝的不能为空,并且是对象或者是
if (obj && typeof obj === "object") {
for (let key in obj) {
if (obj.hasOwnProperty(key)) {
if (obj[key] && typeof obj[key] === "object") {
objClone[key] = deepClone(obj[key]);
} else {
objClone[key] = obj[key];
}
}
}
}
return objClone;
}
```
17. js判断是否在iframe中
```
1.方式一
if (self.frameElement && self.frameElement.tagName == "IFRAME") {
alert('在iframe中');
}
2.方式二
if (window.frames.length != parent.frames.length) {
alert('在iframe中');
}
3.方式三
if (self != top) {
alert('在iframe中');
}
以上用任何一种都可以判断代码是否在iframe中.
```
18. 移动端如果使用了faskclick
在IOS下,``需要双击才能打开
```
import FastClick from 'fastclick';
FastClick.attach(document.body); // 解决移动端300ms延迟
```
只需要在元素上增加 class='needsclick'
```
```
19. 过滤数组中属性值相同的项
```js
[
{ a:1, b:4 },
{ a:2, b:4 },
{ a:3, b:5 },
].reduce(
(cur,next) => {
if(!cur.some(x => x.b === next.b)) {
cur.push(next);
}
return cur
},[])
```
20. 过滤表情
```
```
21. 移动端的拖拽
```
mousedown、mousemove、mouseup和touchstart、touchmove、touchend
拖动时候用到的三个事件:mousedown、mousemove、mouseup在移动端都不起任何作用。毕竟移动端是没有鼠标的,查资料后发现,
在移动端与之相对应的分别是:touchstart、touchmove、touchend事件。
还有一点要注意的是在PC端获取当前鼠标的坐标是:event.clientX和event.clientY,
在移动端获取坐标位置则是:event.touches[0].clientX和event.touches[0].clientY。
```
22. 树优化
https://www.cnblogs.com/yuwenjing0727/p/7210625.html
https://github.com/bitmain-frontend/huge-tree
23. node 复制文件和文件夹
```js
var fs = require('fs')
var path = require('path')
var copyFile = function(srcPath, tarPath, cb) {
var rs = fs.createReadStream(srcPath)
rs.on('error', function(err) {
if (err) {
console.log('read error', srcPath)
}
cb && cb(err)
})
var ws = fs.createWriteStream(tarPath)
ws.on('error', function(err) {
if (err) {
console.log('write error', tarPath)
}
cb && cb(err)
})
ws.on('close', function(ex) {
cb && cb(ex)
})
rs.pipe(ws)
}
// 复制目录及其子目录
var copyFolder = function(srcDir, tarDir, cb) {
fs.readdir(srcDir, function(err, files) {
var count = 0
var checkEnd = function() {
++count == files.length && cb && cb()
}
if (err) {
checkEnd()
return
}
files.forEach(function(file) {
var srcPath = path.join(srcDir, file)
var tarPath = path.join(tarDir, file)
fs.stat(srcPath, function(err, stats) {
if (stats.isDirectory()) {
console.log('mkdir', tarPath)
fs.mkdir(tarPath, function(err) {
if (err) {
console.log(err)
return
}
copyFolder(srcPath, tarPath, checkEnd)
})
} else {
copyFile(srcPath, tarPath, checkEnd)
}
})
})
//为空时直接回调
files.length === 0 && cb && cb()
})
}
```
23. 正则表达式
```js
/*
(?=exp) 正向前瞻 匹配后面满足表达式exp的位置
(?!exp) 负向前瞻 匹配后面不满足表达式exp的位置
(?<=exp) 正向后瞻 匹配前面满足表达式exp的位置(JS不支持)
(?