目录
报错:
export 'createStore' (imported as 'createStore') was not found in './store/index.js' (possible exports: default)
原代码:
store中index.js
import {createStore} from 'vuex'
import app from './modules/app'
import user from './modules/user'
import getters from './getters'
import state from './state'
import mutations from './mutations'
export default createStore({
modules: {
app,
user
},
getters,
state,
mutations
})
main.js全局挂载报错
import {createStore} from './store/index.js'
app.use(createStore)
修改后代码:
import {createStore} from 'vuex'
import app from './modules/app'
import user from './modules/user'
import getters from './getters'
import state from './state'
import mutations from './mutations'
const store = createStore({
modules: {
app,
user
},
getters,
state,
mutations
})
export default store;
main.js
import store from './store/index.js'
app.use(store)
在组件使用
import { useStore } from "vuex"
setup(){
const store = useStore()
console.log(store)
}
成功打印,不再报错