How to import Vuex or eventBus.js file in index.js file?
See original GitHub issueI have to develop the communication between my Vue components, either with Vuex state management or with eventBus, but I cannot import the proper *.js file in my index.js. Vuex has already been installed with npm.
I tried something like this: //********************************************************************** store.js:
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
export const store = new Vuex.Store({
state: {
status: []
}
});
//********************************************************************** index.js:
import Vuex from 'vuex';
import store from './store/store'
SBA.use({
install({vue}) {
vue.use(Vuex)
}
})
SBA.use({
install({Vuex}) {
Vuex.use(store)
}
})
//********************************************************************** I get the following error:
store.js: Uncaught TypeError: Cannot read property 'use' of undefined
at eval (store.js:8)
at Module../src/store/store.js (custom.js:1811)
OR after some modification: Uncaught Error: [vuex] must call Vue.use(Vuex) before creating a store instance
I also tried to this, but nothing worked nothing worked:
import Vuex from 'vuex';
import store from './store/store'
SBA.use({
install({viewRegistry,vue}) {
vue.use(Vuex);
vue.use(store);
viewRegistry.addView({
name: 'instances/custom',
parent: 'instances',
path: 'custom',
component: customEndpoint,
label: 'something',
group: 'Group',
order: -10, // Orig: 1000
isEnabled: ({instance}) => instance.hasEndpoint('custom')
});
}
});
How shall I import *.js files properly? Thank you for the help!
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
accessing vuex store in js file - Stack Overflow
The following worked for me: import store from '../store' store.getters.config // => 'config'.
Read more >Using event bus in Vue.js to pass data between components
We're going to create an event bus instance as a separate file, import it into the two components that are going to share...
Read more >Adding the modules to Vuex | Vue.js 3 Cookbook
Open the index.js file in the src/store folder. Import the index.js file from the authentication folder: import Vue from 'vue'; import Vuex from...
Read more >Event Bus implementation in Vue - Binod Mahto - Medium
Step 1: First we will be creating a vuejs application and then creating a global instance of the event bus using the mitt...
Read more >[Solved]-Vue.js 3 Event Bus-Vue.js - appsloveworld.com
Create a file src/composables/useEmitter.js import { getCurrentInstance } from 'vue' export default function useEmitter() { const internalInstance ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
you need to instantiate the store in the install method. You could turn the store into a promise and resolve it in the install method:
(UNTESTED)
the
Vue.use
in the store.js is the problem you should remove this and you also need to move the creation of the store into theinstall
callback.