vue 输入框失焦时做本地存储

<van-field
  v-model="phone"
  name="phone"
  type="digit"
  maxlength="13"
  input-align="right"
  placeholder="请输入11位数字"
  label="手机号"
  @blur="setLocalStorage" />
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) {
   }
 }
}
上一篇:基本的Select语句和起别名的使用


下一篇:JDBS简单编程,连接数据库,在数据库新建表mybase,并插入数据到数据表。