Skip to content

Tour

Used for step-by-step guidance to help users understand page features. Can highlight target elements and display explanation panels near them.

Tip

The Tour component demo behaves abnormally in iframe. You can click the arrow in the top-left corner of the demo to view it separately.

Component Types

Basic Usage

Define guidance steps through steps, control visibility through v-model, and synchronize current step index through v-model:current.

html
<wd-tour v-model="showBasicTour" :steps="basicSteps" v-model:current="current" :padding="10" @finish="handleFinish" @change="handleChange" />
ts
import type { TourChangeDetail, TourStep } from '@/uni_modules/wot-ui/components/wd-tour/types'
import { ref } from 'vue'

const showBasicTour = ref(false)
const current = ref(0)

const basicSteps: TourStep[] = [
  {
    element: '#step1',
    content: 'Welcome to the tour component, this is the first step explanation'
  },
  {
    element: '#step2',
    content: 'This is the second step, showing another feature point'
  }
]

function handleChange({ current }: TourChangeDetail) {
  console.log('Current step:', current)
}

function handleFinish() {
  showBasicTour.value = false
}

Component States

Click Mask to Continue

After setting click-mask-next, clicking the mask layer will automatically proceed to the next step.

html
<wd-tour v-model="showClickMaskTour" :steps="basicSteps" :click-mask-next="true" />

Close Mask

After setting mask to false, only the highlight area and explanation panel remain, without the full-page mask.

html
<wd-tour v-model="showNoMaskTour" :steps="noMaskSteps" :mask="false" />

Component Styles

Custom Mask

You can adjust the highlight area and mask performance through properties like mask-color, offset, border-radius, padding.

html
<wd-tour
  v-model="showCustomMaskTour"
  :steps="customMaskSteps"
  mask-color="red"
  :offset="40"
  :border-radius="15"
  :padding="10"
  next-text="Next"
  prev-text="Previous"
  skip-text="Skip"
  finish-text="Finish"
/>

Custom Highlight Area

Fully take over highlight area rendering through the highlight slot.

html
<wd-tour v-model="showCustomHighlightTour" :steps="customHighlightSteps" :padding="10">
  <template #highlight="{ elementInfo }">
    <view class="custom-highlight" :style="`${objToStyle(elementInfo)};${objToStyle(customHighlightStyle)}`"></view>
  </template>
</wd-tour>
ts
import { objToStyle } from '@/uni_modules/wot-ui/common/util'

const customHighlightStyle = {
  border: '2px dashed #ff0000',
  borderRadius: '8px',
  background: 'rgba(255, 0, 0, 0.1)',
  boxSizing: 'border-box'
}

Custom Content and Buttons

Supports customizing guide content and action buttons through content, prev, next, skip, finish slots.

html
<wd-tour v-model="showCustomContentTour" :steps="customContentSteps" next-text="Continue" prev-text="Back" skip-text="Skip" finish-text="Got it">
  <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>

  <template #next>
    <view class="custom-button custom-next">Next</view>
  </template>

  <template #finish>
    <view class="custom-button custom-finish">Finish</view>
  </template>
</wd-tour>

Special Styles

Control Current Step

You can directly jump to a specified step externally through v-model:current.

ts
const controlCurrent = ref(0)

function startControlTour() {
  controlCurrent.value = 2
  showControlTour.value = true
}

Tour Attributes

ParameterDescriptionTypeDefault Value
model-valueWhether to show guide component, supports v-modelbooleanfalse
stepsGuide step listTourStep[][]
currentCurrent step index, supports v-model:currentnumber0
maskWhether to show maskbooleantrue
mask-colorMask colorstring-
offsetSpacing between guide panel and highlight areanumber20
durationAnimation duration, in millisecondsnumber300
border-radiusHighlight area border radiusnumber4
paddingHighlight area paddingnumber8
prev-textPrevious step button textstringPrevious
next-textNext step button textstringNext
skip-textSkip button textstringSkip
finish-textFinish button textstringFinish
bottom-safety-offsetBottom safety offset, used for scroll calculationnumber100
top-safety-offsetTop safety offset, used for scroll calculationnumber0
custom-navWhether to enable custom navigation bar modebooleanfalse
click-mask-nextWhether to proceed to next step when clicking mask layerbooleanfalse
highlight-styleDefault highlight area styleCSSProperties{}
z-indexZ-indexnumber-
show-tour-buttonsWhether to show guide buttonsbooleantrue
scopeQuery scope, limits selector lookup rangeunknown-
missing-strategyProcessing strategy when target element is missing, optional values are skip, stop, hideMissingStrategystop
custom-classRoot node custom class namestring''
custom-styleRoot node custom stylestring''

TourStep Attributes

ParameterDescriptionTypeDefault Value
elementElement selector to highlightstring-
contentStep explanation, supports rich-text renderingstring-
paddingOverride highlight padding for current stepnumber-
offsetOverride panel spacing for current stepnumber-
placementForce specify hint position, optional values are auto, top, bottom, left, rightTourPlacementauto

Tour Events

Event NameDescriptionParameters
changeTriggered when current step changes{ current: number }
prevTriggered when clicking previous step{ prevCurrent, current, total, isElementInTop }
nextTriggered when clicking next step{ prevCurrent, current, total, isElementInTop }
finishTriggered when clicking finish{ current, total }
skipTriggered when clicking skip{ current, total }
errorTriggered when target element query fails{ message, element }
update:modelValueTriggered when visibility state changesboolean
update:currentTriggered when current step changesnumber

Tour Methods

Method NameDescriptionParametersReturn Value
handlePrevSwitch to previous step--
handleNextSwitch to next step--
handleFinishFinish guide and close component--
handleSkipSkip guide and close component--

Tour Slots

NameDescriptionParameters
highlightCustom highlight area{ elementInfo }
contentCustom guide content-
prevCustom previous step button-
nextCustom next step button-
skipCustom skip button-
finishCustom finish button-

主题定制

CSS 变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 全局配置

名称默认值描述
--wot-tour-z-index999层级
--wot-tour-animation-duration0.3s动画时长
--wot-tour-highlight-animation-timingease-in-out高亮动画时间函数
--wot-tour-highlight-shadow-color$opac-7_55高亮区域阴影颜色
--wot-tour-popover-z-index1000弹层层级
--wot-tour-popover-max-widthcalc($n-1 * 340)弹层最大宽度
--wot-tour-popover-min-widthcalc($n-1 * 200)弹层最小宽度
--wot-tour-popover-bg$filled-oppo弹层背景色
--wot-tour-popover-padding$padding-loose弹层内边距
--wot-tour-popover-radius$radius-main弹层圆角
--wot-tour-info-font-size$typography-body-size-main信息框字号
--wot-tour-info-line-height$typography-body-line--height-size-main信息框行高
--wot-tour-info-color$text-main信息框文字颜色
--wot-tour-buttons-margin-top$spacing-tight操作区域上边距

Source Code

Documentation
Component

Released under the MIT License.

Released under the MIT License.