vuex的commit没有返回值,数据创建后,检查是否成功,
解决方法
1,在声明数据类型时,声明一个Eorr类型的变量,在创建完数据后去读取这个数据的值是为null或者是为Eorr,为null则创建成功
store/index.tsconst store = new Vuex.Store({state: {recordList:[] ,tagList:[] ,currentTag:undefined,createRecordError:null}as RootState,mutations: {...}})
类型声明
//可以放在XXX.d.ts里面也可以放在使用的那个页面里type RootState={recordList: RecordItem[],tagList:Tag[],currentTag?:Tag,createRecordError:null|Error}
2,或者写一个回调函数
在该写异步的地方写异步,同步函数里不要写异步,
============================================
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号