请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

mutation 报错 (已不报错)

图片描述
突然就不报错了 - -
老师您好,在使用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’?

正在回答 回答被采纳积分+3

1回答

张轩 2022-05-15 09:31:08

同学你好 已经解决了是吗?

0 回复 有任何疑惑可以回复我~
  • 提问者 慕侠7521915 #1
    错误自动消失了咯,原因不明
    回复 有任何疑惑可以回复我~ 2022-05-15 16:59:09
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信