add background music
This commit is contained in:
23
nuxt/store/index.js
Normal file
23
nuxt/store/index.js
Normal 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);
|
||||
}
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user