getters 什么时候放到store.getters里面的?只看到读取的时候

来源:12-6 Vuex 初始化(5)

旋涡鸣人_

2019-03-11

function makeLocalGetters (store, namespace) {
  const gettersProxy = {}

  const splitPos = namespace.length
  Object.keys(store.getters).forEach(type => {
    // skip if the target getter is not match this namespace
    if (type.slice(0, splitPos) !== namespace) return

    // extract local getter type
    const localType = type.slice(splitPos)

    // Add a port to the getters proxy.
    // Define as getter property because
    // we do not want to evaluate the getters in this time.
    Object.defineProperty(gettersProxy, localType, {
      get: () => store.getters[type],
      enumerable: true
    })
  })

  return gettersProxy
}


Object.keys(store.getters)

store.getters 啥时候包含那么多东西?

写回答

1回答

ustbhuangyi

2019-03-11

使用的时候啊,你在实例化 Store 的时候,不就传进去了么

0
1
旋涡鸣人_
懂了,。
2019-03-11
共1条回复

Vue.js 源码深入解析 深入理解Vue实现原理

全方位讲解 Vue.js 源码,进阶高级工程师

4984 学习 · 1037 问题

查看课程