浅记typescript中的localstorage

473 阅读1分钟
声明:
recordList:Record[] = JSON.parse(window.localStorage.getItem('recordList')||'');

更新:
@Watch('recordList')
    onRecordListChange(){
        window.localStorage.setItem('recordList',JSON.stringify(this.recordList));
        console.log(window.localStorage.getItem('recordList'));
    }
    
坑:    
updateRecordList(){
    const cloneRecord = JSON.parse(JSON.stringify(this.record));
    this.recordList.push(cloneRecord);
    }
克隆record,避免我们push同一个对象进recordlist