我目前正在使用vuex和typescript,但我的代码中有这个错误,我不知道如何修复它。TS2322: Type '(state: State, exRep: number, exName: string) => void' is not assignable to type 'Mutation '
我的代码:
import { createStore } from "vuex";
import {State} from "./Types";
const store = createStore<State>({
state() {
return {
exercices: []
}
},
mutations: {
addEx(state: State, exRep: number, exName: string) {
const exId = checkid()
state.exercices.push({ "rep": exRep, "name": exName, "id": exId })
},
removeEx(state: State, exoId: Number) {
console.log(exoId)
state.exercices = state.exercices.filter(obj => obj.id !== exoId)
}
}
})
export default store
错误发生在"addEx"突变处
1条答案
按热度按时间nue99wik1#
变异函数只有2个参数,如果它们是可变的,那是不切实际的。第二个参数是可选的有效载荷,如果有多个参数,它应该是一个对象: