Skip to content

Instantly share code, notes, and snippets.

@potato4d
Created August 5, 2018 23:59
Show Gist options
  • Select an option

  • Save potato4d/17091c2fd848b230eee8f864dcb9eed6 to your computer and use it in GitHub Desktop.

Select an option

Save potato4d/17091c2fd848b230eee8f864dcb9eed6 to your computer and use it in GitHub Desktop.
nuxt-client-init-module を使って Nuxt.js にクライアントサイド限定の初期化処理を追加する ref: https://qiita.com/potato4d/items/cc5d8ea24949e86f8a5b
export const state = () => ({
isCalled: false
})
export const getters = {
isCalled: (state) => state.isCalled
}
export const mutations = {
setIsCalled(state) {
state.isCalled = true
}
}
export const actions = {
nuxtClientInit({ commit }, context) {
commit('setIsCalled')
}
}
<template>
<section class="container">
isCalled: {{isCalled}}
</section>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
computed: {
...mapGetters(['isCalled'])
}
}
</script>
{
// ...
modules: [
'nuxt-client-init-module'
],
// ...
}
$ yarn add nuxt-client-init-module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment