1. 數據回顯 -- 修改頁面,根據詳情接口回顯表單數據數組
let utils = { copyObject(target, source) { for (let key in target) { if (source.hasOwnProperty(key)) { target[key] = source[key] } } }, }
請求詳情接口成功後調用:
utils.copyObject(this.submitData, e.body)
2.本地存儲數據類session
class Store { constructor() { this.store = window.sessionStorage this.prefix = 'athena_' } set(key, value) { try { value = JSON.stringify(value) } catch (e) { value = value } console.log(value) this.store.setItem(this.prefix + key, value) } get(key) { if (!key) { throw new Error('沒有找到key') } if (typeof key === 'object') { throw new Error('key不能是一個對象') } let value = this.store.getItem(this.prefix + key) if (value !== null) { try { value = JSON.parse(value) } catch (e) { value = value } } console.log(value) return value } clean(key) { this.store.removeItem(this.prefix + key) } multiClean(keys) { for (let i of keys) { this.clean(i) } } } export const store = new Store()
使用:
import {store} from '@/utils/store'
let temp = store.get('aaa')
3. 對象拷貝this
Object.assign()方法用於將全部可枚舉屬性的值從一個或多個源對象複製到目標對象。它將返回目標對象。spa
4. 數組刪除3d
itemList.removeByProp(model.id, 'id')code