Vue Tour for Vue 3
`vue3-tour` is a lightweight, simple, and customizable tour plugin designed specifically for Vue.js 3 applications. It guides users through an application by highlighting elements and displaying contextual information in a step-by-step fashion. Currently at stable version 1.0.3, it is a direct fork of the popular `vue-tour` library, re-engineered for compatibility with the Vue 3 composition API and ecosystem. While release cadence isn't highly frequent, the project shows ongoing maintenance with recent fixes. Key differentiators include its ease of integration with Vue 3's `createApp` pattern, the ability to target any DOM element via standard CSS selectors, and support for asynchronous `before()` functions in steps for complex UI transitions. It ships with TypeScript types, enhancing developer experience in TypeScript projects.
Common errors
-
TypeError: Cannot read properties of undefined (reading 'start') or TypeError: this.$tours is undefined
cause The `v-tour` component, which registers the tour instance with the given name, has not been rendered or the plugin was not correctly installed via `app.use()`.fixEnsure `app.use(Vue3Tour)` is called in your `main.js/ts` file and that the `<v-tour name="yourTourName" :steps="steps"></v-tour>` component is present and rendered in your application's template hierarchy. -
Module not found: Error: Can't resolve 'vue3-tour/dist/vue3-tour.css'
cause The import path for the CSS file is incorrect.fixVerify the import statement. It must be `import 'vue3-tour/dist/vue3-tour.css'`. -
Tour steps are visible but lack styling (e.g., no arrows, misplaced popovers, basic browser button styling).
cause The default CSS for `vue3-tour` has not been imported or has been inadvertently overridden by other styles.fixAdd `import 'vue3-tour/dist/vue3-tour.css'` to your application's entry file. If already present, inspect your application's styles for conflicts that might be overriding `vue3-tour`'s default CSS rules.
Warnings
- breaking `vue3-tour` is a complete rewrite for Vue 3 and is incompatible with applications built for Vue 2 using the original `vue-tour` library. Direct migration requires updating plugin registration and component usage to Vue 3's API.
- gotcha Tour popovers and navigation elements will appear unstyled or broken if the default CSS is not explicitly imported into your application.
- gotcha If a tour step's `target` selector (e.g., `#my-id`, `.my-class`, `[data-v-step="2"]`) does not match an existing DOM element when the step is activated, the tour step will fail to render correctly or may throw an error.
Install
-
npm install vue3-tour -
yarn add vue3-tour -
pnpm add vue3-tour
Imports
- Vue3Tour
import { Vue3Tour } from 'vue3-tour'import Vue3Tour from 'vue3-tour'
- v-tour
import { VTour } from 'vue3-tour'// Used directly in Vue templates as <v-tour ...>
- styles
import 'vue3-tour/vue3-tour.css'
import 'vue3-tour/dist/vue3-tour.css'
- $tours
this.$tour.start()
this.$tours['myTour'].start()
Quickstart
// main.js
import { createApp } from 'vue';
import App from './App.vue';
import Vue3Tour from 'vue3-tour';
import 'vue3-tour/dist/vue3-tour.css';
const app = createApp(App);
app.use(Vue3Tour);
app.mount('#app');
// App.vue
<template>
<div>
<div id="v-step-0" style="margin: 20px; padding: 10px; border: 1px solid blue;">
A DOM element on your page. The first step will pop on this element.
</div>
<div class="v-step-1" style="margin: 20px; padding: 10px; border: 1px solid green;">
Another element for the second step.
</div>
<div data-v-step="2" style="margin: 20px; padding: 10px; border: 1px solid red;">
The final element for the third step.
</div>
<v-tour name="myTour" :steps="steps"></v-tour>
<button @click="startTour">Start Guided Tour</button>
</div>
</template>
<script>
export default {
name: 'App',
data() {
return {
steps: [
{
target: '#v-step-0',
header: { title: 'Welcome!' },
content: `This is the starting point of our application tour.`,
},
{
target: '.v-step-1',
content: 'Here you will find key information and functionalities.',
},
{
target: '[data-v-step="2"]',
content: 'And this is where you can take action!',
params: { placement: 'top' },
},
],
};
},
methods: {
startTour() {
if (this.$tours && this.$tours['myTour']) {
this.$tours['myTour'].start();
} else {
console.error("Tour 'myTour' not found. Ensure <v-tour name='myTour'> is rendered.");
}
},
},
mounted() {
// Optionally start the tour automatically
// this.startTour();
},
};
</script>