1.自执行函数
(()=>{
})()
2.异步封装
async requestMet(type, url, params) {
if (type == "post") {
let result = await new Promise((resolve, reject) => {
axios.get(url, params)
.then(function (response) {
resolve(response.data)
}, function (err) {
console.log(err);
})
})
return result;
}
}
3.延时器
setTimeout(()=>{
},500)
4.数据结构转换
arr.join(',')
.split(',')
JSON.parse(JSON.stringify())
Object.keys(this.obj).map(key=>{
this.obj[key] = ''
})
5.switch
switch(){
case :return ;break;
}
6.代码规范
`${obj}`
const arr = [1, 2, 3, 4];
const [first, second] = arr;
const a = { k1: v1, k2: v2 };
const b = {
k1: v1,
k2: v2,
};
const a = {};
Object.assign(a, { x: 3 });
const a = { x: null };
a.x = 3;
const itemsCopy = [...items];