|
13 | 13 |
|
14 | 14 | This is a Vue wrapper for the [Shepherd](https://github.com/shipshapecode/shepherd), site tour, library. |
15 | 15 |
|
16 | | -## Installation |
17 | | - |
18 | | -### NPM |
19 | | - |
20 | 16 | ```bash |
21 | 17 | npm install vue-shepherd --save |
22 | 18 | ``` |
23 | 19 |
|
24 | | -When using with a module system, you must explicitly install vue-shepherd via Vue.use(): |
| 20 | +## Usage |
25 | 21 |
|
26 | | -```js |
27 | | -import Vue from 'vue'; |
28 | | -import VueShepherd from 'vue-shepherd'; |
| 22 | +### Composition API (suggested) |
29 | 23 |
|
30 | | -Vue.use(VueShepherd); |
31 | | -``` |
| 24 | +```vue |
| 25 | +<template> |
| 26 | + <div ref="el"> |
| 27 | + Testing |
| 28 | + </div> |
| 29 | +</template> |
32 | 30 |
|
33 | | -## Usage |
| 31 | +<script setup> |
| 32 | + import { ref, onMounted } from 'vue' |
| 33 | + import { useShepherd } from 'vue-shepherd' |
| 34 | +
|
| 35 | + const el = ref(null); |
34 | 36 |
|
35 | | -You will need to import the styles first: |
| 37 | + const tour = useShepherd({ |
| 38 | + useModalOverlay: true |
| 39 | + }); |
| 40 | + |
| 41 | + onMounted(() => { |
| 42 | + tour.addStep({ |
| 43 | + attachTo: { element: el.value, on: 'top' }, |
| 44 | + text: 'Test' |
| 45 | + }); |
36 | 46 |
|
37 | | -```css |
38 | | -@import '~shepherd.js/dist/css/shepherd.css'; |
| 47 | + tour.start(); |
| 48 | + }); |
| 49 | +</script> |
39 | 50 | ``` |
40 | 51 |
|
41 | | -The plugin extends Vue with a set of directives and $shepherd() constructor function. |
| 52 | +### Option API |
42 | 53 |
|
43 | | -### Constructor Function |
| 54 | +To use vue-shepherd with Option API you have to install the plugin which will add the '$shepherd' function to your vue app. |
| 55 | + |
| 56 | +```js |
| 57 | +import { createApp } from 'vue'; |
| 58 | +import VueShepherdPlugin from 'vue-shepherd'; |
| 59 | +import '~shepherd.js/dist/css/shepherd.css'; |
| 60 | + |
| 61 | +createApp().use(VueShepherdPlugin).mount('#app'); |
| 62 | +``` |
44 | 63 |
|
45 | 64 | ```vue |
46 | 65 | <template> |
47 | | - <div> |
| 66 | + <div ref="el"> |
48 | 67 | Testing |
49 | 68 | </div> |
50 | 69 | </template> |
51 | 70 |
|
52 | 71 | <script> |
53 | | - export default { |
54 | | - name: 'ShepherdExample', |
55 | | - mounted() { |
56 | | - this.$nextTick(() => { |
57 | | - const tour = this.$shepherd({ |
| 72 | + import { defineComponent } from 'vue' |
| 73 | +
|
| 74 | + export default defineComponent({ |
| 75 | + data(){ |
| 76 | + return { |
| 77 | + tour: null |
| 78 | + } |
| 79 | + }, |
| 80 | +
|
| 81 | + methods: { |
| 82 | + createTour(){ |
| 83 | + this.tour = this.$shepherd({ |
58 | 84 | useModalOverlay: true |
59 | 85 | }); |
60 | 86 |
|
61 | | - tour.addStep({ |
62 | | - attachTo: { element: this.$el, on: 'top' }, |
| 87 | + this.tour.addStep({ |
| 88 | + attachTo: { element: this.$refs.el, on: 'top' }, |
63 | 89 | text: 'Test' |
64 | 90 | }); |
| 91 | + } |
| 92 | + }, |
| 93 | +
|
| 94 | + created(){ |
| 95 | + this.createTour(); |
| 96 | + }, |
65 | 97 |
|
66 | | - tour.start(); |
67 | | - }); |
| 98 | + mounted(){ |
| 99 | + this.tour.start(); |
68 | 100 | } |
69 | | - }; |
| 101 | + }); |
70 | 102 | </script> |
71 | 103 | ``` |
72 | 104 |
|
73 | | -### Directives |
| 105 | +## Directives |
74 | 106 |
|
75 | 107 | WIP |
0 commit comments