1

这是代码:

<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]),但是当我刷新页面时键和值都消失了。

页面刷新后如何使其保持不变?

4

0 回答 0