Nuxt内にjsonファイルを読み込ませたい、またそのデータをいろんなところで使いたいと思い下記のリンクを参考に作成してみました。
Nuxt.js(v2)で静的なJSONファイルを読み込み、いろんな所で使う。
ほぼ書き方は同じですが
store/json.js
import jsonData from '~/assets/json/menu.json' // 状態管理 export const state = () => ({ data: jsonData, }) // getters export const getters = { getAll: (state) => { // return state.json return state.data } }
componentes/Headers.vue
<template> <pre>{{ jsonAll }}</pre> </template> <script> export default { asyncData ({ store }) { // jsonAll: store.getters['json/getAll'] const jsonAll = store.getters['json/getAll'] return { jsonAll } } } </script>
client.js?06a0:43 [Vue warn]: Property or method "jsonAll" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties. found in ---> <Headders> at components/Headders.vue <VApp> <Layouts/default.vue> at layouts/default.vue <Root>
同じファイルで別の方法を試すも
<template> <pre>{{ getAll() }}</pre> </template> <script> import { mapGetters } from 'vuex' export default { methods: { ...mapGetters({ getAll: 'json/getAll' }) } } </script>
unknown getter: json/getAll
pages/index.vueにdataとして保存するやりかたなどが必要なのでしょうか?
いずれもすんなり行かず。
試してみたほうがいい方法や、他に必要な情報等がありましたが追記しましすのでご回答よろしくお願いします。
環境
Nuxt + Vuetify
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/03/04 12:45
2020/03/04 12:58
2020/03/04 13:24
2020/03/04 13:31
2020/03/05 05:45
2020/03/05 11:57