Skip to content

Instantly share code, notes, and snippets.

@cieux1
Created January 10, 2019 06:04
Show Gist options
  • Select an option

  • Save cieux1/5dd268e5409320a362df05329b721aa4 to your computer and use it in GitHub Desktop.

Select an option

Save cieux1/5dd268e5409320a362df05329b721aa4 to your computer and use it in GitHub Desktop.
for nuxtjs blog post
// store/index.js
const createStore = () => {
return new Vuex.Store({
state: {
isNewHighScore: false,
bgSong: {}
},
mutations: {
setIsNewHighScore(state) {
state.isNewHighScore = true;
},
setBgSong(state) {
state.bgSong = new Audio("lucky_game.mp3");
state.bgSong.loop = true;
state.bgSong.volume = 0.3;
}
}
}
// pages/index.vue
<template>
<div>
<div v-if="$store.state.isNewHighScore">
This will be displayed when you had a new high score!
</div>
</div>
</template>
<script>
export default {
data() {
return {
//......
}
},
methods: {
init() {
this.initSongs();
},
initSongs() {
this.$store.commit("setBgSong");
// Other songs and sound etc..
}
}
//.....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment