Vuex 和 Redux 文档将箭头函数显示为对象方法

问题描述 投票:0回答:0

我在 vuex 文档和 redux 中看到过很多次使用箭头函数作为对象方法,但我不明白为什么。为什么不使用常规对象方法,因为商店是一个对象?是不是因为在引擎盖下使用了代理而无关紧要?

vue

const store = createStore({
  data: () => ({
    count: 0
  }),
  methods: {
    increment(state) {
      state.count++
    }
  }
})

redux

const counterSlice = createSlice({
  name: 'counter',
  initialState: {
    value: 0
  },
  reducers: {
    incremented: state => {
      state.value += 1
    }
  }
})
javascript vue.js vuex
© www.soinside.com 2019 - 2024. All rights reserved.