wieerwill.github.io/nuxt/store/index.js

23 lines
757 B
JavaScript
Raw Normal View History

2021-07-06 07:04:28 +00:00
export const state = () => ({
isSoundEnabled: true,
})
export const mutations = {
toggleSound(state) {
state.isSoundEnabled = !state.isSoundEnabled;
localStorage.setItem('isSoundEnabled', state.isSoundEnabled);
},
initializeSound(state) {
const isSoundEnabled = JSON.parse(localStorage.getItem('isSoundEnabled'));
if (!isSoundEnabled) {
state.isSoundEnabled = false;
localStorage.setItem("isSoundEnabled", false);
} else if (isSoundEnabled) {
state.isSoundEnabled = true;
localStorage.setItem("isSoundEnabled", true);
} else {
state.isSoundEnabled = true;
localStorage.setItem("isSoundEnabled", true);
}
},
}