vuex如何设置state里面的属性全部为null?

state里面很多属性 我想在某个mutation中把state里面的值全部设置为null
如果一个个去这样this.state.routeName=null设置太麻烦了 因为state里面的属性太多了 有什么简单的办法吗?

mutation.js

setNull () {
    
}

state.js

export default {
  routeName: '',
  auth: 1,
  list: ['a', 'b', 'c'],
  navShow: true,
  files: null
}
阅读 2.8k
1 个回答
setNull: (state) => {
  Object.keys(state).forEach(e => {
     state[e] = null
  })
}
推荐问题