vuex 的 mutations 里,因为要设置 state 里属性的值,我想这样做:
vue 里:
this.$store.commit('setValue', ['token','example'])
vuex 里:
setValue(state, [key, val]:any) {
state[key] = val
}
上面代码是用数组传值,但是改用对象传值也是一样,在用中括号引用属性时报错:
Element implicitly has an 'any' type because expression of type 'any' can't be used to index type……
我刚用 typescript,折腾了一番没能解决,请问这种情况应该怎么处理呢?求教~
state
需要设置类型,最简单的state:any