mutation 报错 (已不报错)
来源:6-11 Vuex 整合当前应用
慕侠7521915
2022-05-14
突然就不报错了 - -
老师您好,在使用mutation时,出现如上错误
具体对应课程的 “6-11 Vuex 整合当前应用” 的第9分钟
以下是store.ts 页面代码:
import { createStore } from 'vuex’
import { testData, testPost, ColumnProps, PostProps } from './testData’
interface UserProps {
isLogin: boolean;
name?: string;
id?: number;
}
export interface GlobalDataProps {
columns: ColumnProps[];
posts: PostProps[];
user: UserProps;
}
// GlobalDataProps传入到createStore泛型中
const store = createStore({
state: {
columns: testData,
posts: testPost,
user: {
isLogin: false
}
},
mutation: {
login(state) {
state.user = { …state.user, isLogin:true, name: ‘慕课’ }
}
}
})
export default store
以下是错误信息:
Argument of type ‘{ state: { columns: ColumnProps[]; posts: PostProps[]; user: { isLogin: false; }; }; mutation: { login(state: any): void; }; }’ is not assignable to parameter of type ‘StoreOptions’.
Object literal may only specify known properties, but ‘mutation’ does not exist in type ‘StoreOptions’. Did you mean to write ‘mutations’?
1回答
-
张轩
2022-05-15
同学你好 已经解决了是吗?
012022-05-15