nipplejs icon indicating copy to clipboard operation
nipplejs copied to clipboard

[FEAT] Vue /Nuxt integration example?

Open a1xon opened this issue 5 years ago • 2 comments

It would be very helpful to see an example where this library is integrated in a vue/nuxt enviroment.

a1xon avatar Aug 01 '20 01:08 a1xon

I ended up injecting the nipple.min.js file via plugins It works but I'm not sure if this is the way to go :\

a1xon avatar Aug 01 '20 02:08 a1xon

I'm using it with Quasar something like this: (in SPA mode; with Nuxt in Universal mode you'd have to wrap the mounted in a

if (process.browser) { }

block, but the same setup should work without plugins (although plugins work well too; it's really all a matter of whether you want the component to be global or not):

<template>
  <div class="virtual--gamepad">
  </div>
</template>

<script>
import nipplejs from 'nipplejs'

export default {
  name: 'VirtualGamepad',
  mounted () {
    // eslint-disable-next-line no-unused-vars
    const staticGamepad = nipplejs.create({
      zone: document.querySelector('.virtual--gamepad'),
      mode: 'static',
      position: { left: '50%', top: '50%' },
      color: '#c9c3b2',
      threshold: 0.25,
      fadeTime: 400,
      maxNumberOfNipples: 1
    })
  }
}
</script>

mtpiercey avatar Aug 05 '20 03:08 mtpiercey