如何与根Vuex文件进行交互?

时间:2019-10-31 02:18:05

标签: javascript vue.js vuex nuxt.js

有这样的存储代码index.js

export const state = () => ({
  dbIndexData: null,
});

export const mutations = {

  init_data_for_index (state, uploadDbIndexData) {
    state.dbIndexData = uploadDbIndexData;
  },

};

export const actions = {
  async init_data_for_index2 ({commit, categories}) {
    commit('init_data_for_index', categories);
  },
};

还有1页+ 1个组件与其交互:

主页:index.vue

<template>

  <div class="wrapper">
    <HeaderApp>
    </HeaderApp>

    <CenterContentIndexApp>
    </CenterContentIndexApp>

    <FooterApp>
    </FooterApp>

  </div>

</template>

<script>
  //index
  import axios from 'axios';
  import HeaderApp from '~/components/HeaderApp';
  import CenterContentIndexApp from '~/components/CenterContentIndexApp';
  import FooterApp from '~/components/FooterApp';

  export default{

  fetch ({ store, params }) {
    return axios.get('https://seo-gmbh.eu/json/api_sunds.php?action=get_pages&url=index')
    .then((res) => {
      store.dispatch('init_data_for_index2', res.data);
    })
  },


    components:{
      HeaderApp,
      CenterContentIndexApp,
      FooterApp,
    },

}

</script>

及其组件CenterContentIndexApp:

<template>

  <section class="center_content_index">
    <ul class="ul_1">

        <LiServiceApp
          v-for="i in $store.state.index.dbIndexData.data.activities"
          :item="i"
          :key="i.id">
        </LiServiceApp>

    </ul>
    <!--  <ul class="ul_1"> end -->

  </section>

</template>


<script>

  import LiServiceApp from '~/components/CenterContentIndexApp/LiServiceApp';

  export default{

    data: function(){
      return{

        data1: '',

      }
    },


    components:{
      LiServiceApp,
    },


}
</script>

我的问题是:
以前,我使用IndexPage.js作为根存储的名称,并且在连接到存储对象时,我还访问了该名称-一切对我都有效,没有失败。
这是没有任何错误的工作代码:
https://github.com/Mike-Kharkov/mike_kharkov_repositiry/tree/Mike-Kharkov-patch-1
但! 我发现给出这样的名称是不正确的,有必要精确地将其命名为index.js!

我以适当的方式对其进行了更改并更改了连接到该存储对象的路径(改为单词index而不是IndexPage),我收到了以下计划的错误:

我还必须更改提取以在某些地方分派并添加操作。

http://joxi.ru/Y2LlMPYC7kKJ82 http://joxi.ru/52aXbPzUEVPq5m

有人知道为什么该页面无法在当前配置中工作以及如何解决该问题吗?

0 个答案:

没有答案