Created
August 5, 2018 23:59
-
-
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
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
| 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') | |
| } | |
| } |
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
| <template> | |
| <section class="container"> | |
| isCalled: {{isCalled}} | |
| </section> | |
| </template> | |
| <script> | |
| import { mapGetters } from 'vuex' | |
| export default { | |
| computed: { | |
| ...mapGetters(['isCalled']) | |
| } | |
| } | |
| </script> |
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
| { | |
| // ... | |
| modules: [ | |
| 'nuxt-client-init-module' | |
| ], | |
| // ... | |
| } |
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
| $ yarn add nuxt-client-init-module |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment