well, I have to ask and answer myself again. In the middle of the night, there are still a lot of back-end interfaces left undone. I looked at the vuex source code and didn't find the answer I wanted. Finally came up with a crooked method. (enough nonsense)
solution:
when solving this problem, you should never think like this: "the vuex in the plug-in is relatively independent of the vuex in the project that references the plug-in." what do you mean? That means you can't completely encapsulate the store in your plug-in, just register the plug-in when referencing the plug-in, and then vuex,store will happy alone in its own small scope. In fact, this is what I originally intended to look like, but I couldn't find a solution. Ask the god for advice! )
based on the above wrong ideas, half a day is gone. And then my solution was,
use vuex's module.
Yes, at the beginning of vuex design, in order to prevent all the state (state) from being put together, the state was too large to be maintained, so the state of the module using module, was well managed separately.
here, I encapsulate all my state management into a module, and export this module by the way when exporting the plug-in.
example
//moduleStore.js
const state={
editorContent:'editorContent',
};
const mutations={};
const actions={};
const getters={
getEditorContent(state){
return state.editorContent;
}
};
const editorStore={
state,
mutations,
actions,
getters
}
export default editorStore;
//plugin index.js
import module from './moduleStore.js'
const plugin={
install:(Vue,options)=>{
}
}
export const ms=module; //
export const pl=plugin;
well, in that case, it's basically done. What should I do when using the plug-in?
first of all,
// main.js
import {pl} from 'plugin'; //
Vue.use(pl) //
here, the import of the plug-in is registered, and then, in the global Vuex store,
//index.js
import {ms} from 'plugin' // vuex store
// ms modules
const modules={
ms,
}
so far, the plug-in is fully integrated with the project
I have the following questions:
1, how to use vuex inside the plug-in
2, how to export the plug-in, through module.exports. Can
be exported in a named way instead of what you call, export const ms=module; / / here, and cannot be exported by default
my requirement is to import plug-ins in the form of npm packages import
look for a reply and write. -,