运行vuex报出如下错误
发布于 9天前 作者 18759967903 143 次浏览 来自 问答

运用vuex时报出,[Vue warn]: Error in render: "TypeError: Cannot read property ‘getters’ of undefined",请大神看看, 附上全部文件代码,请好心的大神指导下是哪里出了问题 store.js文件 import Vue from “vue” import Vuex from ‘vuex’ Vue.use(Vuex); import mutations from ‘./mutations’ import actions from ‘./actions’ export default new Vuex.Store({ actions, modules:{ mutations }, })


App.vue文件 <template>

<Top v-show="topShow"></Top> <router-view></router-view>
</template> <script> import Top from './components/top.vue' import Footer from './components/footer.vue' import {mapGetters,mapActions} from 'vuex' export default { name: 'App', computed:mapGetters([ 'topShow' ]), watch:{ $route(to,from){ if(to.path == "/communication"){ this.$store.dispatch('hideTop') }else { this.$store.dispatch('showTop') } } }, components:{ Top, Footer, } } </script> ----------------------------------------------------------- actions.js文件 export default { showTop({commit}){ commit('showTop') }, hideTop({commit}){ commit('hideTop') }, } --------------------------------------------------- muattions.js文件 import getters from './getters' const state={ top:true }; const mutations={ showTop(state){ state.top=true; }, hideTop(state){ state.top=false; } } export default { state, mutations, getters, } ------------------------------------------------------ getters.js文件 export default { topShow(state){ return state.top } } --------------------------------------------------------------- main.js文件 import router from './router' import VueAwesomeSwiper from 'vue-awesome-swiper' import Store from './store/store.js'

import ‘swiper/dist/css/swiper.css’ import ‘…/node_modules/bootstrap/dist/css/bootstrap.min.css’ import ‘…/node_modules/bootstrap/dist/js/bootstrap.min.js’

Vue.use(VueAwesomeSwiper) Vue.config.productionTip = false

new Vue({ el: '#app’, Store, router, components: { App }, template: '<App/>' })

1 回复

说了getters是undefined了

回到顶部