2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

vuexでmapStateのimportの仕方を間違えてた話

2
Posted at

問題

mapStateを使って、stateをコンポーネントで使おうとしたとき、
Error: [nuxt] Error while mounting app: TypeError: Object(...) is not a function
とコンソールに表示され、画面が表示されなくなった

問題のコード↓

hoge.vue
<script>
import mapState from 'vuex'

export default {
  computed: mapState(`fuga`, {
    isPiyo: `isPiyo`
  })
}
</script>

間違ってたところ

mapStateはだけimportするときも

hoge.vue
<script>
import { mapState } from 'vuex'

~~~~

</script>

と書かなければならななかった。

自分はてっきり{ }

hoge.vue
<script>
import { mapState, mapAction } from 'vuex'

~~~~

</script>

のように複数のmap〇〇ヘルパーをimportするときに使うだけだと勘違いしていた。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?