vue3 pinia 使用问题?

引入方式
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
}
阅读 1.7k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题