1👍
✅
Your values start again at zero because you constantly start from your this.diaAnterior
variable which, at each reload, becomes an empty array. So, you find yourself push
your new value into an empty array each time you reload.
You have to get the value of your localStorage, store it in this.diaAnterior
and then push
your result to add a new value to the old ones.
In code it would look like this:
guardarDiaAnterior() {
const resultStorage = JSON.parse(localStorage.getItem('resultado'))
if (resultStorage){
this.diaAnterior = resultStorage
}
this.diaAnterior.push(this.resultado)
localStorage.setItem('resultado',JSON.stringify(this.diaAnterior))
this.ayer= JSON.parse(localStorage.getItem('resultado'))
},
Source:stackexchange.com