feat(projects): add pinia setup syntax example: setup-store[添加setup syntax的pinia示例setup-store]

This commit is contained in:
Soybean
2022-09-21 18:14:57 +08:00
parent a539112a0f
commit 82c4b09b94
4 changed files with 51 additions and 0 deletions

View 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);
};
}
}