mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
feat(projects): add pinia setup syntax example: setup-store[添加setup syntax的pinia示例setup-store]
This commit is contained in:
21
src/store/plugins/index.ts
Normal file
21
src/store/plugins/index.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import type { PiniaPluginContext } from 'pinia';
|
||||
import { cloneDeep } from 'lodash-es';
|
||||
|
||||
/**
|
||||
* setup语法的重置状态插件
|
||||
* @param context
|
||||
* @description 请将用setup语法的状态id写入到setupSyntaxIds
|
||||
*/
|
||||
export function resetSetupStore(context: PiniaPluginContext) {
|
||||
const setupSyntaxIds = ['setup-store'];
|
||||
|
||||
if (setupSyntaxIds.includes(context.store.$id)) {
|
||||
const { $state } = context.store;
|
||||
|
||||
const defaultStore = cloneDeep($state);
|
||||
|
||||
context.store.$reset = () => {
|
||||
context.store.$patch(defaultStore);
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user