createId
class 封装法
let id = 0
class Id{
value: number;
constructor(){
id +=1
this.value = id
}
}
函数封装法
let id =parseInt(window.localStorage.getItem('idMax') || '0' );
const createId = () => {
id += 1;
window.localStorage.setItem('idMax',JSON.stringify(id))
return id;
};
/、写入 localStorage
其他
深拷贝
const clone = JSON.parse(JSON.stringfy(tags))
Omit
type RecordItem = {
tagIds: number[],
note: string,
category: '-' | '+',
amount: number,
createAt:string
}
type newRecordItem = Omit<RecordItem, 'createAt'>
Partial
Partial<typeof selected>