1

请问大神们这种是什么写法呢 'delete'(state, { payload: id })

reducers: {
    'delete'(state, { payload: id }) {
      return state.filter(item => item.id !== id);
    },
  }
2019-04-19 提问
3 个回答
1

等于以下写法:

reducers: {
  'delete': function (state, _ref) {
      var id = _ref.payload
      return state.filter(function (item) {
          return item.id !== id
      })
  }
}

叫参数解构

1

{ payload: id } 是对象解构赋值,具体参考 解构赋值 MDN
'delete' 仅仅是对象属性名,事实上,对象的所有属性名都会被转为 String
如果你指的是 'delete'(state, { payload: id }) {} 这种函数写法的话,则可以参考 方法的定义 MDN

0

等于如下代码

reducers: {
    delete:(state, { payload: id }) => {
        return state.filter(item => item.id !== id);
    },
}

撰写答案

推广链接