vue driver.js頁面分步引導

卡姿蘭大長腿發表於2020-08-21

Driver.js基本用法

<template>
  <div class="app-container">
    <aside>
      {{ $t('guide.description') }}
      <a href="https://github.com/kamranahmedse/driver.js" target="_blank">driver.js.</a>
    </aside>
    <el-button icon="el-icon-question" type="primary" @click.prevent.stop="guide">
      {{ $t('guide.button') }}
    </el-button>
  </div>
</template>

<script>
import Driver from 'driver.js' // import driver.js
import 'driver.js/dist/driver.min.css' // import driver.js css
import steps from './steps'

export default {
  name: 'Guide',
  data() {
    return {
      driver: null
    }
  },
  mounted() {
    // this.driver = new Driver({
    //         doneBtnText: "完成", //結束按鈕的文字
    //         stageBackground: "#ffffff", 突出顯示元素的背景顏色
    //         nextBtnText: "下一步", //下一步按鈕的文字
    //         prevBtnText: "上一步", //上一步按鈕的文字
    //         closeBtnText: "關閉" //關閉按鈕的文字
    //         onHighlightStarted:(Element)=> {},//元素即將突出顯示時呼叫
    //         onHighlighted:(Element)=> {},//元素完全突出顯示時呼叫
    //         onDeselected:(Element)=> {},//取消選擇元素時呼叫
    //         onReset:(Element)=> {},//當要清除疊加時呼叫
    //         onNext:(Element)=> {},//在任何步驟中移動到下一步時呼叫
    //         onPrevious :( Element)=> {},//在任何步驟中移動到上一步時呼叫
    //     });
    this.driver = new Driver()
  },
  methods: {
    guide() {
      this.driver.defineSteps(steps)
      this.driver.start()
    }
  }
}
</script>

const steps = [
  {
    element: '#hamburger-container',
    popover: {
      title: 'Hamburger',
      description: 'Open && Close sidebar',
      position: 'bottom'
    }
  },
  {
    element: '#breadcrumb-container',
    popover: {
      title: 'Breadcrumb',
      description: 'Indicate the current page location',
      position: 'bottom'
    }
  },
  {
    element: '#header-search',
    popover: {
      title: 'Page Search',
      description: 'Page search, quick navigation',
      position: 'left'
    }
  },
  {
    element: '#screenfull',
    popover: {
      title: 'Screenfull',
      description: 'Set the page into fullscreen',
      position: 'left'
    }
  },
  {
    element: '#size-select',
    popover: {
      title: 'Switch Size',
      description: 'Switch the system size',
      position: 'left'
    }
  },
  {
    element: '#tags-view-container',
    popover: {
      title: 'Tags view',
      description: 'The history of the page you visited',
      position: 'bottom'
    },
    padding: 0
  }
]

export default steps

相關文章