created () {
let data = window.localStorage.getItem('financialData')
if (data) {
data = JSON.parse(data)
this.nickname = data.nickname
this.phone = data.phone
this.sex = data.sex
}
}
methods: {
setLocalStorage () {
const newData = {
nickname: this.nickname,
phone: this.phone,
sex: this.sex
}
let data = window.localStorage.getItem('financialData')
if (!data) {
data = newData
} else {
data = Object.assign(JSON.parse(data), newData) //form表单提交转json
}
try {
window.localStorage.setItem('financialData', JSON.stringify(data))
} catch (error) {
}
}
}