Browse Source

feat: pinia

chenlei 2 years ago
parent
commit
c6a4be8f4e
6 changed files with 52 additions and 2 deletions
  1. 1 0
      package.json
  2. 25 1
      pnpm-lock.yaml
  3. 7 1
      src/main.ts
  4. 9 0
      src/store/index.ts
  5. 9 0
      src/store/module/base.ts
  6. 1 0
      src/store/types.ts

+ 1 - 0
package.json

@@ -13,6 +13,7 @@
     "core-js": "^3.8.3",
     "element-plus": "^2.3.7",
     "lodash": "^4.17.21",
+    "pinia": "^2.1.4",
     "vue": "^3.2.13",
     "vue-class-component": "^8.0.0-0",
     "vue-router": "^4.0.3"

+ 25 - 1
pnpm-lock.yaml

@@ -17,6 +17,9 @@ dependencies:
   lodash:
     specifier: ^4.17.21
     version: 4.17.21
+  pinia:
+    specifier: ^2.1.4
+    version: 2.1.4(typescript@4.5.5)(vue@3.3.4)
   vue:
     specifier: ^3.2.13
     version: 3.3.4
@@ -2623,6 +2626,10 @@ packages:
       - whiskers
     dev: true
 
+  /@vue/devtools-api@6.5.0:
+    resolution: {integrity: sha512-o9KfBeaBmCKl10usN4crU53fYtC1r7jJwdGKjPT24t348rHxgfpZ0xL3Xm/gLUYnc0oTp8LAmrxOeLyu6tbk2Q==}
+    dev: false
+
   /@vue/eslint-config-typescript@9.1.0(@typescript-eslint/eslint-plugin@5.4.0)(@typescript-eslint/parser@5.4.0)(eslint-plugin-vue@8.0.3)(eslint@7.32.0)(typescript@4.5.5):
     resolution: {integrity: sha512-j/852/ZYQ5wDvCD3HE2q4uqJwJAceer2FwoEch1nFo+zTOsPrbzbE3cuWIs3kvu5hdFsGTMYwRwjI6fqZKDMxQ==}
     engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
@@ -7283,6 +7290,24 @@ packages:
     engines: {node: '>=8.6'}
     dev: true
 
+  /pinia@2.1.4(typescript@4.5.5)(vue@3.3.4):
+    resolution: {integrity: sha512-vYlnDu+Y/FXxv1ABo1vhjC+IbqvzUdiUC3sfDRrRyY2CQSrqqaa+iiHmqtARFxJVqWQMCJfXx1PBvFs9aJVLXQ==}
+    peerDependencies:
+      '@vue/composition-api': ^1.4.0
+      typescript: '>=4.4.4'
+      vue: ^2.6.14 || ^3.3.0
+    peerDependenciesMeta:
+      '@vue/composition-api':
+        optional: true
+      typescript:
+        optional: true
+    dependencies:
+      '@vue/devtools-api': 6.5.0
+      typescript: 4.5.5
+      vue: 3.3.4
+      vue-demi: 0.14.5(vue@3.3.4)
+    dev: false
+
   /pkg-dir@4.2.0:
     resolution: {integrity: sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ==}
     engines: {node: '>=8'}
@@ -9089,7 +9114,6 @@ packages:
     resolution: {integrity: sha512-TCTIul70LyWe6IJWT8QSYeA54WQe8EjQFU4wY52Fasj5UKx88LNYKCgBEHcOMOrFF1rKGbD8v/xcNWVUq9SymA==}
     engines: {node: '>=4.2.0'}
     hasBin: true
-    dev: true
 
   /typescript@5.1.3:
     resolution: {integrity: sha512-XH627E9vkeqhlZFQuL+UsyAXEnibT0kWR2FWONlr4sTjvxyJYnyefgrkyECLzM5NenmKzRAy2rR/OlYLA1HkZw==}

+ 7 - 1
src/main.ts

@@ -1,5 +1,11 @@
 import { createApp } from 'vue';
 import App from './App.vue';
 import router from './router';
+import { createPinia } from 'pinia';
 
-createApp(App).use(router).mount('#app');
+export const app = createApp(App);
+
+app.use(router);
+app.use(createPinia());
+
+app.mount('#app');

+ 9 - 0
src/store/index.ts

@@ -0,0 +1,9 @@
+import useBaseStore from './module/base';
+
+export default function useStore() {
+  return {
+    base: useBaseStore(),
+  };
+}
+
+export * from './types';

+ 9 - 0
src/store/module/base.ts

@@ -0,0 +1,9 @@
+import { defineStore } from 'pinia';
+import type { BaseStateType } from '../types';
+
+const useBaseStore = defineStore('base', {
+  state: (): BaseStateType => ({}),
+  actions: {},
+});
+
+export default useBaseStore;

+ 1 - 0
src/store/types.ts

@@ -0,0 +1 @@
+export interface BaseStateType {}