INNER CODE UNIT · JavaScript
state
VueTubeApp/VueTube · NUXT/store/history/index.js:1
export const state = () => ({
historyVideos: [],
});
export const mutations = {
initHistory(state) {
if (process.client) {
// read local storage and parse the list of objects
state.historyVideos = localStorage
.getItem("historyVideos")
.split(",")
.map((video) => JSON.parse(video));
}
},
addHistory(state, video) {
state.historyVideos = state.historyVideos.filter((v) => v.id != video.id); // remove video if it is already in the history list
state.historyVideos.unshift(video);
localStorage.setItem(