Skip to content

Tour

A component used to guide users step-by-step through application features, capable of highlighting specific elements on the page and providing explanations.

Basic Usage

Set the guide steps via the steps prop, and control visibility via v-model.

html
<template>
  <view>
    <view class="tour-item" id="step1">
      <text class="tour-title">Step 1</text>
      <text class="tour-content">This is the first step, introducing basic features</text>
    </view>
    
    <view class="tour-item" id="step2">
      <text class="tour-title">Step 2</text>
      <text class="tour-content">This is the second step, showing more features</text>
    </view>
    
    <wd-tour 
      :model-value="showTour" 
      :steps="steps" 
      v-model:current="current"
      @finish="onFinish"
    />
  </view>
</template>

<script lang="ts" setup>
import { ref } from 'vue'

const showTour = ref(true)
const current = ref(0)

const steps = [
  {
    element: '#step1',
    content: 'This is the explanation for step 1'
  },
  {
    element: '#step2',
    content: 'This is the explanation for step 2'
  }
]

function onFinish() {
  console.log('Tour finished')
}
</script>

Custom Content

Customize the guide content via the content slot.

html
<wd-tour :model-value="showTour" :steps="steps">
  <template #content>
    <view class="custom-content">
      <wd-icon name="help-circle-filled" size="22px"></wd-icon>
      <text class="custom-text">Custom guide content area</text>
    </view>
  </template>
</wd-tour>

Custom Highlight Area

Customize the highlight area style via the highlight slot.

html
<wd-tour :model-value="showTour" :steps="steps">
  <template #highlight="{ elementInfo }">
    <view class="custom-highlight" :style="getCustomHighlightStyle(elementInfo)"></view>
  </template>
</wd-tour>

Custom Buttons

Customize buttons via prev, next, skip, and finish slots.

html
<wd-tour :model-value="showTour" :steps="steps" next-text="Continue" finish-text="Got it">
  <template #next>
    <view class="custom-button custom-next">Next Step</view>
  </template>
  <template #finish>
    <view class="custom-button custom-finish">Finish</view>
  </template>
</wd-tour>

Click Mask to Next

Set whether clicking the mask proceeds to the next step via the click-mask-next prop.

html
<wd-tour 
  :model-value="showTour" 
  :steps="steps" 
  :click-mask-next="true"
/>

Custom Mask Style

Customize mask style via mask-color, offset, border-radius, and padding props.

html
<wd-tour 
  :model-value="showTour" 
  :steps="steps" 
  mask-color="rgba(255, 0, 0, 0.6)"
  :offset="40"
  :border-radius="15"
  :padding="20"
/>

Disable Mask

Control whether to show the mask via the mask prop.

html
<wd-tour 
  :model-value="showTour" 
  :steps="steps" 
  :mask="false"
/>

Control Current Step

Control the current step via v-model:current.

html
<view>
  <wd-button @click="current = 2">Jump to Step 3</wd-button>
  <wd-tour 
    :model-value="showTour" 
    :steps="steps" 
    v-model:current="current"
  />
</view>

Attributes

AttributeDescriptionTypeOptional ValuesDefault
v-modelWhether to show the tour componentboolean-false
stepsList of tour stepsarray-[]
currentCurrent step index, supports v-model:current bindingnumber-0
maskWhether to show the maskboolean-true
mask-colorMask color (supports rgba format)string-rgba(0, 0, 0, 0.5)
offsetSpacing between the tooltip and the highlight boxnumber-20
durationAnimation duration (ms)number-300
border-radiusBorder radius of the highlight areanumber-8
paddingPadding of the highlight areanumber-8
prev-textText for the "Previous" buttonstring-Previous
next-textText for the "Next" buttonstring-Next
skip-textText for the "Skip" buttonstring-Skip
finish-textText for the "Finish" buttonstring-Finish
highlight-styleStyle of the highlight areaobject--
bottom-safety-offsetBottom safety offset, used to ensure enough space around the element during scroll calculationnumber-100
top-safety-offsetTop safety offset, used to ensure enough space around the element during scroll calculationnumber-0
custom-navWhether the navigation bar is customboolean-false
click-mask-nextWhether clicking the mask proceeds to the next stepboolean-false
z-indexZ-index of the tour componentnumber-999
show-tour-buttonsWhether to show tour buttonsboolean-true
scopeQuery scope (limit selector range)object--
missing-strategyStrategy for handling missing elements'skip' | 'stop' | 'hide'-stop

Steps Data Structure

PropertyDescriptionType
elementSelector for the element to highlightstring
contentGuide text content (supports rich text)string
paddingOverride padding for the current stepnumber
offsetOverride spacing between tooltip and highlight for the current stepnumber
placementForce tooltip placement'auto' | 'top' | 'bottom' | 'left' | 'right'

Events

Event NameDescriptionParameters
changeTriggered when the step changes{ current: number }
prevTriggered when the previous button is clicked{ prevCurrent: number, current: number, total: number, isElementInTop: boolean }
nextTriggered when the next button is clicked{ prevCurrent: number, current: number, total: number, isElementInTop: boolean }
finishTriggered when the finish button is clicked{ current: number, total: number }
skipTriggered when the skip button is clicked{ current: number, total: number }
errorTriggered when finding the guide element fails{ message: string, element: string }

Slots

Slot NameDescriptionParameters
highlightCustom highlight areaelementInfo: Element position info
contentCustom guide content-
prevCustom previous button-
nextCustom next button-
skipCustom skip button-
finishCustom finish button-

Methods

You can get the component instance via ref and call the methods provided by the component:

Method NameDescriptionParameters
handlePrevSwitch to the previous step-
handleNextSwitch to the next step-
handleSkipSkip the tour-
handleFinishFinish the tour-

Notes

  1. Ensure the element to highlight exists on the page and is selectable.
  2. In case of a custom navigation bar, set custom-nav and an appropriate top-safety-offset value.
  3. The tour component automatically handles scrolling to ensure the highlighted element is within the viewport.
  4. You can control whether to show the mask via the mask prop.
  5. When using a custom highlight area, be careful not to obscure the tour operation buttons.
  6. Slot usage might vary slightly across different platforms (H5, WeChat Mini Program, etc.).
  7. It is recommended to use v-if or v-show conditional rendering to ensure the component is initialized correctly.

Theme Customization

The component supports theme customization via CSS variables. You can modify the following variables:

scss
// Mask color
--wd-tour-mask-color: rgba(0, 0, 0, 0.5);

// Guide popover background color
--wd-tour-popover-bg-color: #ffffff;

// Button background color
--wd-tour-button-primary-bg-color: #007aff;

// Button text color
--wd-tour-button-color: #ffffff;

FAQ

Why do custom slots not show up in WeChat Mini Program?

Issues may arise when combining conditional rendering with slots in WeChat Mini Program. It is recommended to use v-show instead of v-if or move the condition inside the slot.

Why does the highlight area flicker?

This is usually caused by element information not being fully retrieved when the component initializes. The component has optimized the initial state to avoid flickering.

How to solve click issues?

If the custom highlight area obscures operation buttons, you can adjust the z-index or modify the style of the custom highlight area to ensure buttons are clickable.

Source Code

Documentation
Component

Released under the MIT License.

Released under the MIT License.