1、安装
yarn add pinia@next
2、使用
a.在main.ts中引用
import {createPinia} from 'pinia' app.use(createPinia())
b.新建文件,
import { defineStore } from 'pinia' export const useTodoStore = defineStore({ id: 'todo', state: () => ({ count: 0, title: "Cook noodles", done:false }) })
c.在vue3的文件中使用
<script setup lang="ts"> import { useTodoStore } from '@/stores/index' const global = useTodoStore() </script> <template> <h2>{{global.count}}</h2> </template>
网友评论