diff --git a/docs/guide/multiple-tours.md b/docs/guide/multiple-tours.md index cab64d5..3fa263a 100644 --- a/docs/guide/multiple-tours.md +++ b/docs/guide/multiple-tours.md @@ -1,42 +1,50 @@ # Multiple Tours -To create multiple tours, you can use the `steps` and `name` prop to switch between different tours. + +To create multiple tours, use the `steps` and `name` props to switch between different tours. ### Defining the tours -First you need to define the steps for each tour. -```vue{3-7,12} - ``` -In this case we are creating two tours `tour1` and `tour2`. -Each with their corresponding steps `tourSteps1` and `tourSteps2`. -The `tourSteps` and `tourName` variables are reactive and can be changed at runtime. +In this case we’re creating two tours, `tour1` and `tour2`, each with their corresponding steps `tourSteps1` and `tourSteps2`. The `tourSteps` and `tourName` refs are reactive and can be changed at runtime. ### Switching between tours -To switch between tours, you just switch the `tourSteps` and `tourName` values. -```vue{10-19} - ``` -Now everytime you call the `switchTour` function, the tour will switch between `tour1` and `tour2`. \ No newline at end of file + +If you do NOT use the watcher, you can still support hot‑switching by calling `startTour()` after changing props: + +```vue{16} +function switchTour() { + if (tourName.value === 'tour1') { + tourSteps.value = tourSteps2; + tourName.value = 'tour2'; + } else { + tourSteps.value = tourSteps1; + tourName.value = 'tour1'; + } + vTour.value?.startTour(); // manual restart when watcher is disabled +} +``` + +Notes + +- Prefer replacing the steps array (immutable update) over mutating it in place so the change is detected reliably. +- For multiple, fully independent tours on the same page, give each `VTour` a unique `name`. IDs, highlight classes, and localStorage keys are scoped by `name`, so tours won’t collide. + +# Saving Progress + +You can save a user’s progress in the browser’s localStorage so they can resume later. + +## Using the `saveToLocalStorage` prop + +Set the `saveToLocalStorage` prop on `VTour` to control if/when progress is saved. Accepted values: `never`, `step`, `end`. The default is `never`. + +```vue + + + +``` + +Notes + +- Keys are scoped by the tour’s `name`. The storage key is `vjt-${name}`. If `name` is empty, the key is `vjt-tour`. +- With multiple tours, give each tour a unique `name` so their progress is isolated. + +### `never` + +No progress is saved. Each start begins from the first step (unless you manually control steps). + +### `step` + +Saves the current step index after each step. If the user leaves mid‑tour, the next start resumes at the saved step for that tour’s `name`. + +- Key format: `localStorage.setItem('vjt-', '')` +- Works per tour. Switching `name` switches the storage key, so tours don’t affect each other. + +### `end` + +Saves only when the tour completes. If the user exits before completion, the next start begins at the first step. + +- Completion flag: `localStorage.setItem('vjt-', 'true')` +- When this flag is present, subsequent `startTour()` calls will no‑op unless you reset. + +### Resetting or clearing progress + +- Programmatic reset (recommended): call `resetTour()` to clear state and, if desired, restart. +- Manual clear: `localStorage.removeItem('vjt-')` + +### Multiple tours and hot‑switching + +- Multiple independent tours: Use distinct `name` values to keep DOM ids, highlight classes, and storage keys separate. +- Swapping tours at runtime (changing `name` and/or `steps`): + - Each tour resumes from its own saved state (for `step`) or completion flag (for `end`), based on the new `name`. + - If you keep the watcher that restarts on prop changes, switching `name`/`steps` will auto‑restart the visible tour using the correct per‑name key. + +Small copy edit: “everytime” → “every time”. diff --git a/src/components/VTour.vue b/src/components/VTour.vue index 6eca314..4e09741 100644 --- a/src/components/VTour.vue +++ b/src/components/VTour.vue @@ -1,6 +1,14 @@