Last active
November 17, 2018 17:49
-
-
Save natemate90/e1c51d4bc2068ac683941a5e1f6ab5a4 to your computer and use it in GitHub Desktop.
Nuxt Vuex Store with dynamic translation slugs example code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
methods: { | |
deLocale() { | |
if (this.hasPageSlugs) { | |
return ( | |
this.localePath(this.slicedPath, "de") + | |
"/" + | |
this.currentPageSlugs.de | |
); | |
} | |
return this.switchLocalePath("de"); | |
}, | |
enLocale() { | |
if (this.hasPageSlugs) { | |
return ( | |
this.localePath(this.slicedPath, "en") + | |
"/" + | |
this.currentPageSlugs.en | |
); | |
} | |
return this.switchLocalePath("en"); | |
} | |
}, | |
computed: { | |
...mapState({ | |
currentPageSlugs: state => state.currentPageSlugs | |
}), | |
...mapGetters(["hasPageSlugs"]), | |
localeActive() { | |
return this.$i18n.locale; | |
}, | |
slicedPath() { | |
return this.$route.matched[0].name.substring( | |
0, | |
this.$route.matched[0].name.lastIndexOf("-") | |
); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vuex from "vuex"; | |
const createStore = () => { | |
return new Vuex.Store({ | |
state: () => ({ | |
currentPageSlugs: null | |
}), | |
getters: { | |
hasPageSlugs: state => { | |
return state.currentPageSlugs !== null; | |
} | |
}, | |
mutations: { | |
setCurrentPageSlugs(state, payload) { | |
state.currentPageSlugs = payload; | |
}, | |
resetCurrentPageSlugs(state) { | |
state.currentPageSlugs = null; | |
} | |
} | |
}); | |
}; | |
export default createStore; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment