猿问

Vuex的初始化失败,一直显示没有挂载到根组件上,奇怪了!

代码如下

import 'babel-polyfill'

import Vue from 'vue'

import VueRouter from 'vue-router'

import store from './vuex/store'

import http from 'vue-resource'

import App from './App.vue'

import Vuex  from 'vuex'

Vue.use(http)

Vue.use(VueRouter)

Vue.use(Vuex)


Vue.http.options.root = '/root'

Vue.http.options.emulateJSON = true

Vue.config.debug = true


var router = new VueRouter()

require('./routerConfig')(router)


new Vue({

    store: store,

    components: { App }

})

router.start(App, '#app')

然后store文件

import Vuex from 'vuex'

import frontPage from './modules/frontPage'

import viewsPage from './modules/viewsPage'

import commentPage from './modules/commentPage'

import Vue from 'vue'

Vue.use(Vuex)


export default new Vuex.Store({

    modules: {

        frontPage,

        viewsPage,

        commentPage

    }

})

然而控制台的输出却是这样的!

[vuex] store not injected. make sure to provide the store option in your root component.
不知道怎么解决,求助求助!


猛跑小猪
浏览 2313回答 2
2回答

幕布斯6054654

exmaples看一下例子,并不是在入口文件引入Vuex, 还有,入口文件既然用了router则不需要new Vue,Store中也有问题。看看例子吧,照着写一遍就明白了。

拉丁的传说

错误点太多了;router文件只要配置好router就ok了,store只要注册好各个模块的state,mutations就行了,需要注意的就是router里的app.vue文件,需要引入storeapp.vue<script> &nbsp;&nbsp;&nbsp;&nbsp;import&nbsp;store&nbsp;from&nbsp;'./vuex/store.js'; &nbsp;&nbsp;&nbsp;&nbsp;export&nbsp;default{ &nbsp;&nbsp;&nbsp;&nbsp;store, &nbsp;&nbsp;&nbsp;&nbsp;data(){ &nbsp;&nbsp;&nbsp;&nbsp;},&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;components:{ &nbsp;&nbsp;&nbsp;&nbsp;} } </script>
随时随地看视频慕课网APP
我要回答