0👍
Yes, you can use localStorage
or sessionStorage
to achieve this. You just need to convert the object to a string when setting and convert back when using it.
Example:
...
const setState = data => {
state.content = DOMPurify.sanitize(marked(data['content_' + state.locale]))
state.image = 'storage/' + data['image']
}
if (localStorage.getItem('home')) {
const data = JSON.parse(localStorage.getItem('home'))
setState(data[0])
} else {
axios.get('/home')
.then(res => {
localStorage.setItem('home', JSON.stringify(res.data))
setState(res.data[0])
})
}
...
Source:stackexchange.com