Pinia-面试-defineStore与拆包
2026年10月16日·Admin·2 次浏览
面试题:defineStore 两种写法?Store 放哪?
Options 风格
类似 Vuex:state、getters、actions 对象字面量。
Setup 风格
像 setup():ref/reactive/computed 定义状态与计算属性,return 出去;灵活组合 composable。
组织
按业务域拆文件:stores/user.ts、stores/cart.ts;避免单文件巨型 store。
使用注意
Store 在组件外使用时需在 Pinia 已激活之后(app.use(pinia))。