将现有 quasar 应用程序的状态管理系统从 vuex 更改为 pinia

s4e*_*eed 5 quasar-framework vuejs3 pinia

尝试了此链接并使用 Pinia 在 Quasar 创建了我的第一个商店,我还需要手动更改.quasar/app.js以添加 Pinia 商店并使 Pinia 正常运行。

import { Quasar } from 'quasar'
import { markRaw } from 'vue'
import RootComponent from 'app/src/App.vue'

import createStore from 'app/src/stores/index'
import createRouter from 'app/src/router/index'

export default async function (createAppFn, quasarUserOptions) {
  // Create the app instance.
  // Here we inject into it the Quasar UI, the router & possibly the store.
  const app = createAppFn(RootComponent)
  app.config.devtools = true
  

  app.use(Quasar, quasarUserOptions)

    const store = typeof createStore === 'function'
      ? await createStore({})
      : createStore

    
      app.use(store)
  const router = markRaw(
    typeof createRouter === 'function'
      ? await createRouter({store})
      : createRouter
  )

    // make router instance available in store
    
      store.use(({ store }) => { store.router = router })

  // Expose the app, the router and the store.
  // Note that we are not mounting the app here, since bootstrapping will be
  // different depending on whether we are in a browser or on the server.
  return {
    app,
    store,
    router
  }
}
Run Code Online (Sandbox Code Playgroud)

但问题是,.quasar/app.js一旦执行就会用默认内容重写quasar dev,并且我再次无法再访问 Pinia 商店。

正如我所说,这个应用程序以前是基于 vuex 的。

小智 0

就我而言,我不需要编辑任何特殊文件,只需替换文件夹index.js中的文件即可stores。为了让 quasar CLI 在运行时使用 pinia,quasar new store我必须使用quasar cleanand 就像我已经完全过渡一样。