这是代码:
<todo>
<form onsubmit={ handleSubmit }>
</form>
this.items = []
handleSubmit(e) {
var input = e.target[0]
this.items.push(input.value)
localStorage.setItem('todos', JSON.stringify(this.items))
input.value = ''
console.log(localStorage.getItem('todos'))
}
</todo>
console.log(localStorage.getItem('todos'))
会显示关键字和值(例如["one", "two]
),但刷新页面后,键和值都会消失。
如何在页面刷新后使其保持不变?