You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 26, 2018. It is now read-only.
> This plugin requires Vue >= 2.0. For the Vue 1.\*-compatible version, see the `1.0` branch
10
11
11
-
- Available through npm as `vue-touch`.
12
12
13
-
```js
14
-
var VueTouch =require('vue-touch')
15
-
Vue.use(VueTouch)
16
-
```
13
+
### npm
14
+
15
+
Available through npm as `vue-touch`. As this version is currently in BETA, you have to install with the `next` tag.
16
+
17
+
```bash
18
+
npm install vue-touch@next
19
+
```
20
+
21
+
```Javascript
22
+
var VueTouch =require('vue-touch')
23
+
Vue.use(VueTouch, {name:'v-touch'})
24
+
```
25
+
You can pass an options object as the second argument, which at the moment accepts one property, `name`. It's used to define the name of the component that is registered with Vue and defaults to `'v-touch'`.
17
26
18
27
#### Direct include
19
28
20
-
-You can also directly include it with a `<script>` tag when you have Vue and Hammer.js already included globally. It will automatically install itself, and will add a global `VueTouch`.
29
+
You can also directly include it with a `<script>` tag when you have Vue and Hammer.js already included globally. It will automatically install itself, and will add a global `VueTouch`.
<!-- Render as other elements with the 'tag' prop -->
40
+
<v-touchtag="a"v-on:tap="onTap">Tap me!</v-touch>
41
+
```
42
+
43
+
## API
44
+
45
+
### Component Events
46
+
47
+
vue-touch supports all Hammer Events ot of the box, just bind a listener to the component with `v-on` and vue-touch will setup the Hammer Manager & Recognizer for you.
> **Warning**: You have to register your custom events *before* installing the plugin with `Vue.use(VueTouch)`.
175
+
VueTouch will log a warning to the console (in dev mode) if you try to do that afterwards, and the event will not work.
176
+
177
+
This will make it possible to listen for this event on `<v-touch>`. Additionally, just like for "normal" events, you can pass further options as the corresponding prop.
See [Hammer.js documentation](http://hammerjs.github.io/getting-started/) for all available events.
69
-
70
185
See `/example` for a multi-event demo. To build it, run `npm install && npm run build`.
71
186
187
+
## Server-Side Rendering (SSR)
188
+
189
+
As of the moment of this writing, requiring HammerJS in a non-browser-environment (like during the build process of your SSR bundle) throws an error ([hammerjs/hammerjs#1060](https://github.com/hammerjs/hammer.js/issues/1060)).
190
+
191
+
The easiest fix to that is to use a webpack alias to replace the hammerjs package with a module that just exports a stub, i.e. an empty object. vue-touch comes with such a module, called `hammer-ssr.js`
192
+
```JavaScript
193
+
alias: {
194
+
'hammerjs$':'vue-touch/dist/hammer-ssr.js'
195
+
}
196
+
```
197
+
198
+
Once this issue has been resolved HammerJS, this alias is no longer nessessary and can be removed.
199
+
200
+
The `<v-touch>` component itself will never try to setup any Hamer Manangers or Recognizers if it detects that it is running in an SSR environment (seeVue.js API docs for [vm.$isServer](https://vuejs.org/v2/api/#vm-isServer)). The component will only render a normal `<div>` element (or whatever element you defined with the `tag` prop).
201
+
202
+
## Known Limitations & Bugs
203
+
204
+
* Curently, changing `-options` props will not change recogizer settings. The initial values will stay in place until the component is re-created.
205
+
206
+
## TODO
207
+
208
+
*[ ] Support updating recognizer options when props change.
209
+
*[ ] Find out if e2e tests are possible(contribution welcome)
console.log(`[vue-touch] Your should never see this message.
4
+
When you do, your code tried to call 'new Hammer(), but your app has included a stub for HammerJS, provided by vue-touch, instead of the actual HammerJS library.
0 commit comments