Skip to content

[vue] 你有写过vuex中store的插件吗? #539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
haizhilin2013 opened this issue Jul 2, 2019 · 1 comment
Open

[vue] 你有写过vuex中store的插件吗? #539

haizhilin2013 opened this issue Jul 2, 2019 · 1 comment
Labels
vue vue

Comments

@haizhilin2013
Copy link
Collaborator

[vue] 你有写过vuex中store的插件吗?

@haizhilin2013 haizhilin2013 added the vue vue label Jul 2, 2019
@lostimever
Copy link

Vuexstore 接受 plugins 选项,这个选项暴露出每次 mutation 的钩子。Vuex 插件就是一个函数,它接收 store 作为唯一参数:

const myPlugin = store => {
  // 当 store 初始化后调用
  store.subscribe((mutation, state) => {
    // 每次 mutation 之后调用
    // mutation 的格式为 { type, payload }
  });
};

然后像这样使用:

const store = new Vuex.Store({
  // ...
  plugins: [myPlugin]
});

官方文档

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vue vue
Projects
None yet
Development

No branches or pull requests

2 participants