开发者社区> 问答> 正文

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

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

展开
收起
游客7iokfgo4yexey 2020-05-23 20:58:16 1296 0
1 条回答
写回答
取消 提交回答
  • Vuex 的 store 接受 plugins 选项,这个选项暴露出每次 mutation 的钩子。Vuex 插件就是一个函数,它接收 store 作为唯一参数:

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

    const store = new Vuex.Store({ // ... plugins: [myPlugin] }); 问题来源于GitHub,查看更多答案,请查看https://github.com/haizlin/fe-interview/issues/539

    2020-05-24 12:01:50
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
利用编译将 Vue 组件转成 React 组件 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载