引入方式
store.js
import { createPinia } from 'pinia'
const store = createPinia()
export const setupStore = app => {
app.use(store)
}
export default setupStore
main.js
const app = createApp(App)
// 安装初始化store
setupStore(app)
这么使用正确吗? 让store = reactive({})?
const store = reactive({
id: '',
})
const commit = (fun) => {
if (!fun || typeof fun !== 'function') return
const data = fun(store)
Object.assign(store, data || {})
}
export default {
data: store,
commit
}
官网:https://pinia.vuejs.org