add background music

This commit is contained in:
2021-07-06 09:04:28 +02:00
parent 838fa50add
commit a501b37e57
6 changed files with 117 additions and 3 deletions

23
nuxt/store/index.js Normal file
View File

@@ -0,0 +1,23 @@
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);
}
},
}