Skip to content

Commit

Permalink
feat(docs): Mention usage of Pinia in preFetch for SSR too (quasarfra…
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoenescu committed Apr 7, 2022
1 parent 39d141f commit 33a05bf
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
15 changes: 12 additions & 3 deletions docs/src/pages/quasar-cli-vite/prefetch-feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,26 +177,35 @@ If `redirect(false)` is called (supported only on client-side!), it aborts the c
The `redirect()` method requires a Vue Router location Object.

### Using preFetch to Initialize Pinia or Vuex Store(s)

The `preFetch` hook runs only once, when the app boots up, so you can use this opportunity to initialize the Pinia store(s) or the Vuex Store here.

```js
// -- Pinia on Non SSR --

// App.vue - handling Pinia stores
// example with a store named "myStore"
// placed in /src/stores/myStore.js|ts

import { useMyStore } from 'stores/myStore'

// Non-SSR usage

export default {
// ...
preFetch () {
const myStore = useMyStore()
// do something with myStore
}
}
```

```js
// -- Pinia on SSR --

// SSR usage
// App.vue - handling Pinia stores
// example with a store named "myStore"
// placed in /src/stores/myStore.js|ts

import { useMyStore } from 'stores/myStore'

export default {
// ...
Expand Down
23 changes: 22 additions & 1 deletion docs/src/pages/quasar-cli-webpack/prefetch-feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,13 @@ If `redirect(false)` is called (supported only on client-side!), it aborts the c

The `redirect()` method requires a Vue Router location Object.

### Using preFetch to Initialize the Store
### Using preFetch to Initialize Pinia or Vuex Store(s)

The `preFetch` hook runs only once, when the app boots up, so you can use this opportunity to initialize the Pinia store(s) or the Vuex Store here.

```js
// -- Pinia on Non SSR --

// App.vue - handling Pinia stores
// example with a store named "myStore"
// placed in /src/stores/myStore.js|ts
Expand All @@ -193,6 +196,24 @@ export default {
}
```

```js
// -- Pinia on SSR --

// App.vue - handling Pinia stores
// example with a store named "myStore"
// placed in /src/stores/myStore.js|ts

import { useMyStore } from 'stores/myStore'

export default {
// ...
preFetch ({ store }) {
const myStore = useMyStore(store)
// do something with myStore
}
}
```

```js
// App.vue - handling Vuex store

Expand Down
12 changes: 2 additions & 10 deletions ui/dev/src/pages/components/portal-focus.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
<template>
<div class="q-layout-padding">
<!--
This is for fast tests.
Use this page but don't add it into your commits (leave it outside
of your commit).
For some test that you think it should be persistent,
make a new *.vue file here or in another folder under /dev/components.
-->
<div class="q-pa-md">
<div class="q-mb-md">Should focus on the dialog input after showing</div>

<q-btn label="DIALOG" color="primary" @click="icon = true" />

<q-btn color="primary" label="MENU" class="q-ml-md">
<q-menu no-refocus>
<q-menu>
<q-list dense style="min-width: 100px">
<q-item clickable v-close-popup @click="icon = true">
<q-item-section>DIALOG</q-item-section>
Expand Down

0 comments on commit 33a05bf

Please sign in to comment.