1.新建store文件夹,新建index.ts 2.使用es6的模块化语法导出 import {defineStore} from 'pinia' 3.使用export const useUserStore = defineStore('user', {}) defineStore方法有两个参数,第1个参数是模块化名字,第2个参数是选项,对象里面有3个属性. vuex相比,没有mutations. 4.state(){return{}} 是一个函数返回一个对象,对象里面就是可以共享的状态 5.getters{}:相当于计算属性,computed 6.actions:{} 一个对象,可以定义方法修改state里面的数据,可以是同步,可以是异步。