diff --git a/src/store/index.ts b/src/store/index.ts index d335514..2e046eb 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -1,35 +1,29 @@ -/* - * @Author: 刘引 liu.yin.work@foxmail.com - * @Date: 2023-08-01 13:46:06 - * @LastEditors: 刘引 liu.yin.work@foxmail.com - * @LastEditTime: 2023-08-01 15:56:19 - * @FilePath: \kthec-emss-web\src\pinia\index.js - * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE - */ -import { defineStore } from 'pinia' // 定义容器 - -export let useStore = defineStore('useStore', { - /** - * 存储全局状态 - * 1.必须是箭头函数: 为了在服务器端渲染的时候避免交叉请求导致数据状态污染 - * 和 TS 类型推导 - */ - state: () => { - return { - count: 0, - list: [1, 2, 3, 4] - } - }, - /** - * 用来封装计算属性 有缓存功能 类似于computed - */ - getters: {}, - /** - * 编辑业务逻辑 类似于methods - */ - actions: { - changeData(val: number) { - this.count = val + 10 - } - } -}) +import { createPinia } from 'pinia' +const store = createPinia() +export { store } +export * from './modules/user' +// export let useStore = defineStore('useStore', { +// /** +// * 存储全局状态 +// * 1.必须是箭头函数: 为了在服务器端渲染的时候避免交叉请求导致数据状态污染 +// * 和 TS 类型推导 +// */ +// state: () => { +// return { +// count: 0, +// list: [1, 2, 3, 4] +// } +// }, +// /** +// * 用来封装计算属性 有缓存功能 类似于computed +// */ +// getters: {}, +// /** +// * 编辑业务逻辑 类似于methods +// */ +// actions: { +// changeData(val: number) { +// this.count = val + 10 +// } +// } +// }) diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts new file mode 100644 index 0000000..449279c --- /dev/null +++ b/src/store/modules/user.ts @@ -0,0 +1,10 @@ +import { defineStore } from 'pinia' +import { reactive } from 'vue' + +export const useUserStore = defineStore('useUserStore', () => { + const userInfo = reactive({ + name: 'yin.liu', + age: 18 + }) + return { userInfo } +}) diff --git a/src/views/home/components/news.vue b/src/views/home/components/news.vue index da156b7..f43132b 100644 --- a/src/views/home/components/news.vue +++ b/src/views/home/components/news.vue @@ -1,21 +1,11 @@ - 我是home组件的子组件news - + \ No newline at end of file + diff --git a/src/views/index.vue b/src/views/index.vue index 098cade..8c3a3be 100644 --- a/src/views/index.vue +++ b/src/views/index.vue @@ -1,14 +1,14 @@ - 根组件{{ store.count }} - 测试 + {{ userStore.userInfo.age }} + 测试
{{ userStore.userInfo.age }}